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; }
int KeyboardUpdate() { do { if (KeyboardAddress == 0) { UsbCheckForChange(); if (KeyboardCount() == 0) { KeyboardAddress = 0; return 0; } KeyboardAddress = KeyboardGetAddress(0); if (KeyboardAddress == 0) { return 0; } } int i; for (i=0; i<6; i++) { KeyDown[i] = KeyboardGetKeyDown(KeyboardAddress, i); } } while (KeyboardPoll(KeyboardAddress) != 0); return KeyboardAddress; }
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; }
/* * keyboard_update * Based on * http://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/os/input01.html * * 1. Retrieve a stored keyboard address (initially 0). * 2. If this is not 0, go to 9. * 3. Call UsbCheckForChange to detect new keyboards. * 4. Call KeyboardCount to detect how many keyboards are present. * 5. If this is 0 store the address as 0 and return; we can't do anything with * no keyboard. * 6. Call KeyboardGetAddress with parameter 0 to get the first keyboard's * address. * 7. Store this address. * 8. If this is 0, return; there is some problem. * 9. Call KeyboardGetKeyDown 6 times to get each key currently down and store * them * 10. Call KeyboardPoll * 11. If the result is non-zero go to 3. There is some problem (such as * disconnected keyboard). */ void keyboard_update() { int keyboard_count; int i; do { if (keyboard_address == 0) { UsbCheckForChange(); keyboard_count = KeyboardCount(); kprintf("Got %d keyboard\n", keyboard_count); if (keyboard_count == 0) { keyboard_address = 0; kprintf("No keyboard found\n", keyboard_count); return; } keyboard_address = KeyboardGetAddress(0); if (keyboard_address == 0) { kprintf("Error! Keyboard address is %d\n", keyboard_address); return; } } // Call KeyboardGetKeyDown 6 times to get each key currently down and store // them for (i = 0; i < 6; i += 1) { old_keys[i] = KeyboardGetKeyDown(keyboard_address, i); } } while (KeyboardPoll(keyboard_address) != 0); return; }
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; }