Keyboard inb(0x60) Can not find out key on KeyUp
Posted: Wed Jun 01, 2016 7:26 am
Hi,
I am trying to figure out which key was pressed when the keyboard reports a KeyUp in the status_register.
I can figure out which key is pressed when the key go's down but not when it go's up.
For example when I:
- press 'k'
- then press 'f' without releasing 'k'
- then release 'k'
- then release 'f'
The I get:
- KeyDown 'k'
- KeyDown 'f'
- KeyUp
- KeyUp
The code I use, looks similar to the following:
How can I find out which key was released?
I am trying to figure out which key was pressed when the keyboard reports a KeyUp in the status_register.
I can figure out which key is pressed when the key go's down but not when it go's up.
For example when I:
- press 'k'
- then press 'f' without releasing 'k'
- then release 'k'
- then release 'f'
The I get:
- KeyDown 'k'
- KeyDown 'f'
- KeyUp
- KeyUp
The code I use, looks similar to the following:
Code: Select all
static char* _qwertzuiop = "qwertzuiop"; // 0x10-0x1c
static char* _asdfghjkl = "asdfghjkl";
static char* _yxcvbnm = "yxcvbnm";
static char* _num = "123456789";
char keyboard_to_ascii(uint8_t key)
{
//kprintf("key=0x%x\n", key);
if(key == 0x1C) return '\n';
if(key == 0x39) return ' ';
if(key == 0xE) return '\r';
if(key == POINT_RELEASED) return '.';
if(key == SLASH_RELEASED) return '/';
if(key == ZERO_PRESSED) return '0';
if(key >= ONE_PRESSED && key <= NINE_PRESSED)
return _num[key - ONE_PRESSED];
if(key >= 0x10 && key <= 0x1C)
{
return _qwertzuiop[key - 0x10];
} else if(key >= 0x1E && key <= 0x26)
{
return _asdfghjkl[key - 0x1E];
} else if(key >= 0x2C && key <= 0x32)
{
return _yxcvbnm[key - 0x2C];
}
return 0;
}
uint8_t status_register = inb(0x64);
if (status_register & (1 << 0))
{
uint8_t cc = inb(0x60);
if ((cc & 128) == 128)
{
char c = keyboard_to_ascii(cc);
puts("KeyUp:"); // cc <=== is the key I pressed.
}
else
{
char c = keyboard_to_ascii(cc); // <=== is always blank.
puts("KeyDown:"); //
}
}