Example #1
0
static int
keyboard_getchar (void)
{
	u8 key;
	int c;

	spinlock_lock (&keyboard_lock);
retry:
	key = keyboard_getkey ();
	c = keycode_to_ascii (key);
	if (c < 0)
		goto retry;
	spinlock_unlock (&keyboard_lock);
	return c;
}
Example #2
0
void keyboard_handler(regs *r){
  uint8_t scancode;
  KEYCODE key;
  
  // Read the scan code only if the keyboard controller output buffer is full.
  if (kybrd_ctrl_read_status() & KYBRD_CTRL_STATS_MASK_OUT_BUF) {
      //read the code
      scancode = keybrd_enc_read_buf();
      key = scan_code[scancode];
      //Check if CAPS or SHIFT or any special key is pressed
      if(scancode == 0xE0 || scancode == 0xE1){}
      else{
          // See if this is break code. i.e Test bit 7 of the received scan code
          if(scancode & 0x80){
              // convert the break code into its make code equivalent. The make code
              // and break codes are separated by 0x80
              scancode -= 0x80;
              key = scan_code[scancode];
              switch(key){
                  case KEY_LCTRL:
                  case KEY_RCTRL:
                          _ctrl = FALSE;
                          break;

                  case KEY_LSHIFT:
                  case KEY_RSHIFT:
                          _shift = FALSE;
                          break;

                  case KEY_LALT:
                  case KEY_RALT:
                          _alt = FALSE;
                          break;
                  default:
                          break;
              }
          }
          else{
              //This is a make code
              
              key = scan_code[scancode];

              switch(key){
                  case KEY_LCTRL:
                  case KEY_RCTRL:
                          _ctrl = TRUE;
                          break;

                  case KEY_LSHIFT:
                  case KEY_RSHIFT:
                          _shift = TRUE;
                          break;

                  case KEY_LALT:
                  case KEY_RALT:
                          _alt = TRUE;
                          break;

                  // We handle only the make code for CAPSLOCK.
                  // Break for CAPSLOCK does not matter
                  case KEY_CAPSLOCK:
                          _caps = (_caps) ? FALSE : TRUE;
                          break;
                  default:
                            write_char(TEXT_COLOR,keycode_to_ascii(key));    
                          if(reading){
                            //printf("calling ip buff\n");
                            write_io_buff(keycode_to_ascii(key));
                            }
                          break;
              }

          }
      }
  }
}