Пример #1
0
int main(int argc, char** argv)
{
	char* p;
	key_s* nextKey;
	nextKey->type=(KB_CODE_TYPE*)malloc(sizeof(KB_CODE_TYPE));
	nextKey->val=(char*)malloc(sizeof(char));
	nextKey->buf=(alt_u8*)malloc(sizeof(alt_u8));
	kb=initKb((void*)kb_ISR);
	if(kb==0)
	{
		printf("Fatal error: no keyboard attached");
		return 0;

	}
	while(1)
	{

		if(kb->top!=kb->bottom)
		{
			getchKb(kb, nextKey);
			if(*nextKey->type==KB_ASCII_MAKE_CODE)
				printf("%c",*nextKey->val);

			else if(*nextKey->type==KB_BINARY_MAKE_CODE)
			{
				translate_make_code(*nextKey->type,*nextKey->buf,p);
				printf("BINARY MAKE CODE: %s %d\n",p,*nextKey->buf);
			}
			else if(*nextKey->type==KB_LONG_BINARY_MAKE_CODE)
			{
				translate_make_code(*nextKey->type,*nextKey->buf,p);
				printf("LONG BINARY MAKE CODE: %s %d\n",p,*nextKey->buf);
			}
			else if(*nextKey->type==KB_BREAK_CODE || *nextKey->type==KB_LONG_BREAK_CODE)
				printf("BREAK : %x\n",*nextKey->buf);
			else if(*nextKey->type==KB_INVALID_CODE)
				printf("\nINVALID CODE\n");

		}

	}

	return 0;
}
Пример #2
0
char getKey(){
	if(byte1 != BREAKCODE){				//checks if the received scancode is a BREAKCODE indicator, 0xF0
		translate_make_code(KB_ASCII_MAKE_CODE, (char *) byte1, &ascii);			//if not, translates it to ascii
	}

	char tempo = ascii[0];

	if(strcmp(ascii, "KP 8") == 0){
		return UP;
	}else if(strcmp(ascii, "KP 2") == 0){
		return DOWN;
	}else if(strcmp(ascii, "KP 6") == 0){
		return RIGHT;
	}else if(strcmp(ascii, "KP 4") == 0){
		return LEFT;
	}else if((tempo >='A' && tempo <= 'Z')){			//checks wether or not the received byte is a letter
		if(strlen(ascii) == 1){
			tempo = tempo + 32;						//makes it a small letter instead of a capital
			return tempo;							//returns the character
		}
	}
	return 0;									// returns null
}