char KeyboardGetChar() { if (KeyboardAddress == 0) return 0; int i; for (i=0; i<6; i++) { int key = KeyboardGetKeyDown(KeyboardAddress, i); if (key == 0) break; if (KeyWasDown(key)) continue; if (key > 103) continue; char * table = KeysNormal; struct KeyboardModifiers modifiers = KeyboardGetModifiers(KeyboardAddress); if (modifiers.LeftShift || modifiers.RightShift) table = KeysShift; char value = table[key]; if (value != 0) return value; } return 0; }
void KeyboardManager::serviceIRQ( void ) { KeyboardPoll(usb_kbd_addr_); uint8 scancode = KeyboardGetKeyDown(usb_kbd_addr_,0); if (scancode > 0x80 || scancode == 0) { current_key_ = 0; return; } struct KeyboardModifiers km = KeyboardGetModifiers(usb_kbd_addr_); uint8 key = 0; if (scancode <= 0x40 && (km.LeftShift || km.RightShift)) key = E0_KEYS[scancode]; else // numpad not yet implemented key = STANDARD_KEYMAP[scancode]; if (key != current_key_) { if(main_console) { keyboard_buffer_.put( key ); // put it inside the buffer main_console->addJob(); } } current_key_ = key; }
/* * keyboard_get_char * * 1. Check if KeyboardAddress is 0. If so, return 0. * 2. Call KeyboardGetKeyDown up to 6 times. Each time: * 2.1 If key is 0, exit loop. * 2.2 Call KeyWasDown. If it was, go to the next key. * 2.3 If the scan code is more than 103, go to the next key. * 2.4 Call KeyboardGetModifiers * 2.5 If shift is held, load the address of KeysShift. Otherwise load * KeysNormal. * 2.6 Read the ASCII value from the table. * 2.7 If it is 0, go to the next key otherwise return this ASCII code and * exit. * 3. Return 0. */ int keyboard_get_char() { int i, index, key; BYTE modifiers, ascii_char; index = 0; assert(keyboard_address != 0); for (i = 0; i < 6; i += 1) { key = KeyboardGetKeyDown(keyboard_address, index); if (key == 0) { return 0; } if ((key > 103) || (key_was_down(key) == TRUE)) { continue; } modifiers = KeyboardGetModifiers(keyboard_address); /* 0x22: 0b00100010: Right shift and Left Shift */ if (modifiers & 0x22) { ascii_char = keys_shift[key]; } else { ascii_char = keys_normal[key]; } if (ascii_char != 0) { return ascii_char; } } return 0; }
/* ============= KeyCodeToGlut ============= */ int Keyboard::KeyCodeToGlut( WPARAM code ) { bool isShift = ( KeyboardGetModifiers()&1 ) ? true : false; bool isCtrl = ( KeyboardGetModifiers()&2 ) ? true : false; if( isCtrl ) { if( code >= VK_LETTER_A && code <= VK_LETTER_Z ) { code -= VK_LETTER_A - 1; return code; } }//ctrl switch( code ) { case VK_BACK: return 8; case VK_DELETE: return 127; case VK_RETURN: return '\r'; case VK_LEFT: return 100; //GLUT_KEY_LEFT; case VK_RIGHT: return 102; //GLUT_KEY_RIGHT; case VK_NUMBER_0: return ( isShift ? ')' : code ); case VK_NUMBER_1: return ( isShift ? '!' : code ); case VK_NUMBER_2: return ( isShift ? '@' : code ); case VK_NUMBER_3: return ( isShift ? '#' : code ); case VK_NUMBER_4: return ( isShift ? '$' : code ); case VK_NUMBER_5: return ( isShift ? '%' : code ); case VK_NUMBER_6: return ( isShift ? '^' : code ); case VK_NUMBER_7: return ( isShift ? '&' : code ); case VK_NUMBER_8: return ( isShift ? '*' : code ); case VK_NUMBER_9: return ( isShift ? '(' : code ); case VK_OEM_PERIOD: return ( isShift ? ',' : '.' ); case VK_OEM_MINUS: return ( isShift ? '_' : '-' ); case VK_OEM_PLUS: return ( isShift ? '+' : '=' ); }//switch code if( code >= VK_LETTER_A && code <= VK_LETTER_Z && !isShift ) { //without shift code += 32; } return code; }//KeyCodeToGlut
int keyboard_get_char_intr(volatile unsigned int kbd_address) { int i, index, key; short *tmp; BYTE modifiers, ascii_char; index = 0; assert(kbd_address != 0); for (i = 0; i < 6; i += 1) { key = KeyboardGetKeyDown(kbd_address, index); if (key == 0) { reset_keys_buffer(new_keys_ptr); ascii_char = 0; break; } if ((key > 103) || (key_was_down_intr(key) == TRUE)) { *(new_keys_ptr + i) = key; continue; } modifiers = KeyboardGetModifiers(kbd_address); /* 0x22: 0b00100010: Right shift and Left Shift */ if (modifiers & 0x22) { ascii_char = keys_shift[key]; } else { ascii_char = keys_normal[key]; } if (ascii_char != 0) { *(new_keys_ptr + i) = key; break; } } tmp = old_keys_ptr; old_keys_ptr = new_keys_ptr; new_keys_ptr = tmp; return ascii_char; }