#include "handle.h"
#include "keys.h"
#include <stdio.h>

int main(void){
	t_key a = 0;
	t_ascii ch = 0;

	key_init();
	key_switch("en");
	while(1){
		/*a = key_read();*/
		a = key_raw();
		ch = (t_ascii) (a & KEYMASK_BITS);
		printf("Read key: raw: %u, code: %u, translation: %s%s", a,
			a & KEYMASK_BASIC,
			((a & KEYMASK_CTRL) ? "ctrl " : ""),
			((a & KEYMASK_ALT) ? "alt " : ""));
		if(key_isprintable(ch)){
			printf("%c\n", ch);
		}else{
			if(ch >= 256){
				printf("%s\n", key_to_name(ch));
			}else{
				printf(".\n");
			}
		}
		if((a & KEYMASK_LCTRL) && (a & KEYMASK_RCTRL) && (a & KEYMASK_LALT) &&
				(a & KEYMASK_RALT) && (ch == 'c' || ch == 'C')){
			break;
		}
		if((a & KEYMASK_CTRL) && ch == W_KEY_F1){
			printf("Switch to en keyb: %d\n", key_switch("en"));
		}
		if((a & KEYMASK_CTRL) && ch == W_KEY_F2){
			printf("Switch to pc2 keyb: %d\n", key_switch("pc2"));
		}
		if((a & KEYMASK_CTRL) && ch == W_KEY_F3){
			printf("Switch to kam keyb: %d\n", key_switch("kam"));
		}
	}
	key_shut();
	return 0;
}

/* vim: set ts=4 cindent shiftwidth=4 tw=0 : */
