MonkOS  v0.1
A simple 64-bit operating system (x86_64)
keyboard.h File Reference

Keyboard input routines. More...

#include <core.h>

Go to the source code of this file.

Data Structures

struct  key_t
 A record representing the state of the keyboard at the time a key was presssed or unpressed. More...
 
struct  keylayout_t
 A map of keyboard scan codes to key codes. More...
 

Macros

#define KEYBRK_DOWN   0
 Key-down break code. More...
 
#define KEYBRK_UP   1
 Key-up break code. More...
 
#define META_SHIFT   (1 << 0)
 Set while the shift key is pressed. More...
 
#define META_CTRL   (1 << 1)
 Set while the ctrl key is pressed. More...
 
#define META_ALT   (1 << 2)
 Set while the alt key is pressed. More...
 
#define META_ESCAPED   (1 << 3)
 Set if key's scan code is escaped. More...
 
#define META_CAPSLOCK   (1 << 4)
 Set while caps lock is on. More...
 
#define META_NUMLOCK   (1 << 5)
 Set while num lock is on. More...
 
#define META_SCRLOCK   (1 << 6)
 Set while scroll lock is on. More...
 

Typedefs

typedef enum keycode keycode_t
 

Enumerations

Functions

void kb_init ()
 Initialize the keyboard so that it can provide input to the kernel. More...
 
void kb_setlayout (keylayout_t *layout)
 Install a new keyboard layout. More...
 
char kb_getchar ()
 Return the next available character from the keyboard's input buffer. More...
 
bool kb_getkey (key_t *key)
 Return the available next key from the keyboard's input buffer. More...
 
uint8_t kb_meta ()
 Return the current meta-key bit mask. More...
 

Detailed Description

Keyboard input routines.

Definition in file keyboard.h.


Data Structure Documentation

struct key

A record representing the state of the keyboard at the time a key was presssed or unpressed.

Definition at line 87 of file keyboard.h.

Data Fields
uint8_t brk KEYBRK_UP or KEYBRK_DOWN.
uint8_t meta Metakey mask when key was generated.
uint8_t code Keycode value (type = keycode_t).
uint8_t ch Character value, if valid.
struct keylayout

A map of keyboard scan codes to key codes.

Definition at line 101 of file keyboard.h.

Data Fields
uint8_t shifted[128] when shift key is down.
uint8_t unshifted[128] when shift key is up.

Macro Definition Documentation

#define KEYBRK_DOWN   0

Key-down break code.

Definition at line 19 of file keyboard.h.

Referenced by command_run(), and isr_keyboard().

#define KEYBRK_UP   1

Key-up break code.

Definition at line 20 of file keyboard.h.

Referenced by isr_keyboard(), and keycode_run().

#define META_SHIFT   (1 << 0)

Set while the shift key is pressed.

Definition at line 23 of file keyboard.h.

Referenced by isr_keyboard().

#define META_CTRL   (1 << 1)

Set while the ctrl key is pressed.

Definition at line 24 of file keyboard.h.

Referenced by isr_keyboard().

#define META_ALT   (1 << 2)

Set while the alt key is pressed.

Definition at line 25 of file keyboard.h.

Referenced by isr_keyboard(), and keycode_run().

#define META_ESCAPED   (1 << 3)

Set if key's scan code is escaped.

Definition at line 26 of file keyboard.h.

Referenced by addkey(), and isr_keyboard().

#define META_CAPSLOCK   (1 << 4)

Set while caps lock is on.

Definition at line 27 of file keyboard.h.

Referenced by isr_keyboard().

#define META_NUMLOCK   (1 << 5)

Set while num lock is on.

Definition at line 28 of file keyboard.h.

Referenced by isr_keyboard().

#define META_SCRLOCK   (1 << 6)

Set while scroll lock is on.

Definition at line 29 of file keyboard.h.

Referenced by isr_keyboard().

Typedef Documentation

typedef enum keycode keycode_t

Definition at line 80 of file keyboard.h.

Enumeration Type Documentation

enum keycode

Key code values representing individual keys on the keyboard.

Key codes corresponding to printable characters are not listed here, but they are equal in value to their lowercase ASCII representations (e.g., KEY_A = 'a', KEY_1 = '1', etc.).

Enumerator
KEY_BACKSPACE 
KEY_TAB 
KEY_ENTER 
KEY_ESCAPE 
KEY_CTRL 
KEY_SHIFT 
KEY_ALT 
KEY_PRTSCR 
KEY_CAPSLOCK 
KEY_NUMLOCK 
KEY_SCRLOCK 
KEY_INSERT 
KEY_END 
KEY_DOWN 
KEY_PGDN 
KEY_LEFT 
KEY_CENTER 

Keypad Center.

KEY_RIGHT 
KEY_HOME 
KEY_UP 
KEY_PGUP 
KEY_DEL 
KEY_MINUS 

Keypad Minus.

KEY_PLUS 

Keypad Plus.

KEY_F1 
KEY_F2 
KEY_F3 
KEY_F4 
KEY_F5 
KEY_F6 
KEY_F7 
KEY_F8 
KEY_F9 
KEY_F10 
KEY_F11 
KEY_F12 
KEY_SCANESC 

Escaped scan code.

KEY_INVALID 

Invalid scan code.

Definition at line 38 of file keyboard.h.

Function Documentation

void kb_init ( )

Initialize the keyboard so that it can provide input to the kernel.

kb_init installs the default US English PS/2 keyboard layout.

Definition at line 268 of file keyboard.c.

Referenced by kmain().

void kb_setlayout ( keylayout_t *  layout)

Install a new keyboard layout.

Parameters
[in]layoutThe keyboard layout to install.

Definition at line 288 of file keyboard.c.

char kb_getchar ( )

Return the next available character from the keyboard's input buffer.

Returns
The ascii value of the next character in the input buffer, or 0 if there are no characters available.

Definition at line 294 of file keyboard.c.

bool kb_getkey ( key_t *  key)

Return the available next key from the keyboard's input buffer.

Parameters
[out]keyThe key record of the next key in the buffer.
Returns
true if there is a key in the buffer, false otherwise.

Definition at line 318 of file keyboard.c.

Referenced by command_run(), and keycode_run().

uint8_t kb_meta ( )

Return the current meta-key bit mask.

Returns
The meta-key bitmask.

Definition at line 340 of file keyboard.c.