Tvùrce webu je i pro tebe! Postav tøeba web. Bez grafika. Bez kodéra. Hned.
wz

<< Back

cesky: , English:

KEY

Keyboard driver

Keyboard driver in the Litos8 system does not use (unlike other parts of the system) standard BIOS interface, but accesses direct to the ports. The main reason is to allow monitor keystrokes and release of each key (map of keystrokes is available). It is important in games. Another reason is greater comfort in coding keys.

Each pressed key is recorded to the ring key buffer. Key value is encoded into a 2-byte code so that it contains ordinary number of key on kyboard (the scan code), current state of modifiers (Alt, Ctrl and Shift) and the corresponding character value (according to the currently set language selected by Scroll Lock key). Scan code can be basic or extended, due to compatibility with older XT keyboards. The key code may seem quite complicated to use. Therefore there are some functions available, which can extract required information from the key code.

There are several functions to get keys from the ring buffer. Keys can be read either all (including modifiers such as Ctrl, Alt, or Shift), or valid keys without modifiers (modifier codes are emitted from the buffer), or as valid characters - in such case all non-character keys are discharged.

Key code in detail:

bit 15:
0=character key
- bit 8..14: scan code of key (0=generated character)
- bit 0..7: character code (1..0ffh)
1=control, extended or special key
- bit 8..14: scan code of key
- bit 7: 1=extended key (extendend scan)
- bit 6: Alt modifier
- bit 5: Ctrl modifier
- bit 4: Shift modifier
- bit 0..3: tabled ASCII character
....... 0 = non ASCII character (it is control key)
....... 1 = 08h (BS, Ctrl+H, BackSpace)
....... 2 = 09h (TAB, Ctrl+I, Tabelator)
....... 3 = 0Ah (LF, Ctrl+J)
....... 4 = 0Dh (CR, Ctrl+M, Enter)
....... 5 = 1Bh (ESC, Ctrl+[, Esc)
....... 6 = 1Ch (FSEP, Ctrl+"\")
....... 7 = 1Dh (GSEP, Ctrl+])
....... 8 = 1Eh (RSEP, Ctrl+^)
....... 9 = 1Fh (USEP, Ctrl+_)
....... 10 = 20h (SPACE, SpaceBar)
....... 11 = 2Ah ("*")
....... 12 = 2Bh ("+")
....... 13 = 2Dh ("-")
....... 14 = 2Fh ("/")
....... 15 = 7Fh (DEL, Delete)

Alt modifier typically sets the key character value to 0 and changes key to a control key (bit 15 = 1). Ctrl modifier masks character value by 1Fh mask, the other keys (with zero result of masking) changes to control key.

To get scan code of key (0..7Fh, ScanFromKey function):
code = (key >> 8) & 0x7F;

To get extended scan code of key (0..0FFh, ExtFromKey function):
code = (key >> 8) & 0x7F;
if (key < 0) code |= (key & 0x80);

To get modifiers Ctrl, Alt, Shift (0..7, ModiFromKey function):
if (key < 0) modi = ((key >> 4) & 7); else modi = 0;

To get extended scan code with modifiers (0..7FFh, ScanModiFromKey function):
code = (key >> 8) & 0x7F;
if (key < 0) code |= (key & 0x80) | ((key & 0x70) << 4);

To get character (0..0FFh, CharFromKey function):
if (key < 0) ascii = KeyCharTab[key & 0xF]; else ascii = key & 0xFF


SetLang - set language

INPUT:
AL = new
language (LANG_EN, LANG_CS)

NOTES: It temporaly disables interrupts.


GetLang - get current language

OUTPUT:
AL = current
language (LANG_EN, LANG_CS)


TestChar - test if some character is ready

OUTPUT:
AL = character, 0=no character (CY)
CY = no character (AL = 0)

NOTES: Character is not removed from keyboard buffer. It temporaly disables interrupts.


GetChar - get character without waiting

OUTPUT:
AL = character, 0=no character (CY)
CY = no character (AL = 0)

NOTES: It temporaly disables interrupts.


GetCharWait - get character with waiting

OUTPUT:
AL = character (1..0ffh)

NOTES: It temporaly disables interrupts.


TestKey - test if some key is ready

OUTPUT:
AX = key code, 0=no key (CY)
CY = no key (AX = 0)

NOTES: Key is not removed from keyboard buffer. It temporaly disables interrupts.


GetKey - get key without waiting (without modifiers)

OUTPUT:
AX = key code, 0=no key (CY)
CY = no key (AX = 0)

NOTES: It temporaly disables interrupts.


GetKeyWait - get key with waiting (without modifiers)

OUTPUT:
AX = key code

NOTES: It temporaly disables interrupts.


KeyIsModi - check if key is modifier

INPUT:
AX = key code

OUTPUT:
NC = key is modifier (Cltr,ALt,Shift,x Lock)


TestKeyModi - test if some key is ready (incl. modifiers Ctrl,Alt...)

OUTPUT:
AX = key code, 0=no key (CY)
CY = no key (AX = 0)

NOTES: Key is not removed from keyboard buffer. It temporaly disables interrupts.


GetKeyModi - get key without waiting (including modifiers Ctrl, Alt...)

OUTPUT:
AX = key code, 0=no key (CY)
CY = no key (AX = 0)

NOTES: It temporaly disables interrupts.


GetKeyModiWait - get key with waiting (including modifiers Ctrl,Alt...)

OUTPUT:
AX = key code

NOTES: It temporaly disables interrupts.


KeyGetModi - get keyboard modifiers

OUTPUT:
AL = keyboard
modifiers (KEY_MODI_SCROLL, ...)


KeySetModi - set keyboard modifiers (and LEDs)

INPUT:
AL = keyboard
modifiers (KEY_MODI_SCROLL, ...)

NOTES: It temporaly disables interrupts.


KeyFlush - flush keyboard buffer

NOTES: It temporaly disables interrupts.


IsScrollLock - check Scroll Lock state

OUTPUT:
AL = Scroll Lock state (0=OFF and CY, 1=ON and NC)
CY = Scroll Lock is OFF (AL = 0)


IsNumLock - check Num Lock state

OUTPUT:
AL = Num Lock state (0=OFF and CY, 1=ON and NC)
CY = Num Lock is OFF (AL = 0)


IsCapsLock - check Caps Lock state

OUTPUT:
AL = Caps Lock state (0=OFF and CY, 1=ON and NC)
CY = Caps Lock is OFF (AL = 0)


IsInsert - check Insert state

OUTPUT:
AL = Insert state (0=OFF and CY, 1=ON and NC)
CY = Insert is OFF (AL = 0)


IsPause - check Pause state

OUTPUT:
AL = Pause state (0=OFF and CY, 1=ON and NC)
CY = Pause is OFF (AL = 0)


KeySetRate - set keyboard rate

INPUT:
AL = rate coefficient (0..31, 0->30 key/sec ... 31->2 key/sec)
AH = initial delay (0..3, 0->250 ms ... 3->1000 ms)

NOTES: It temporaly disables interrupts.


ReturnKey - return key into keyboard buffer ring (as first key)

INPUT:
AX = key code (should not be 0)

NOTES: It temporaly disables interrupts.


SetKey - write key into keyboard buffer ring (as last key)

INPUT:
AX = key code (should not be 0)

NOTES: It temporaly disables interrupts.


GetKeyMap - get bitmap of pressed keys

OUTPUT:
BX = pointer to 256-bit system key map, 1=key is pressed

NOTES: Use extended scan code as index into key bitmap.


KeyPressed - test if key is pressed

INPUT:
AL = key extended
scan code

OUTPUT:
AL = key status, 1=pressed (NC), 0=released (CY)
CY = key is not pressed (AL = 0)


CtrlPressed - test if left or right Ctrl is pressed

OUTPUT:
AL = key status, 1=pressed (NC), 0=released (CY)
CY = key is not pressed (AL = 0)


LCtrlPressed - test if left Ctrl is pressed

OUTPUT:
AL = key status, 1=pressed (NC), 0=released (CY)
CY = key is not pressed (AL = 0)


RCtrlPressed - test if right Ctrl is pressed

OUTPUT:
AL = key status, 1=pressed (NC), 0=released (CY)
CY = key is not pressed (AL = 0)


AltPressed - test if left or right Alt is pressed

OUTPUT:
AL = key status, 1=pressed (NC), 0=released (CY)
CY = key is not pressed (AL = 0)


LAltPressed - test if left Alt is pressed

OUTPUT:
AL = key status, 1=pressed (NC), 0=released (CY)
CY = key is not pressed (AL = 0)


RAltPressed - test if right Alt is pressed

OUTPUT:
AL = key status, 1=pressed (NC), 0=released (CY)
CY = key is not pressed (AL = 0)


ShiftPressed - test if left or right Shift is pressed

OUTPUT:
AL = key status, 1=pressed (NC), 0=released (CY)
CY = key is not pressed (AL = 0)


LShiftPressed - test if left Shift is pressed

OUTPUT:
AL = key status, 1=pressed (NC), 0=released (CY)
CY = key is not pressed (AL = 0)


RShiftPressed - test if right Shift is pressed

OUTPUT:
AL = key status, 1=pressed (NC), 0=released (CY)
CY = key is not pressed (AL = 0)


ScanFromKey - get base scan code from key code

INPUT:
AX = key code

OUTPUT:
AL = base
scan code (0..7Fh)


ExtFromKey - get extended scan code from key code

INPUT:
AX = key code

OUTPUT:
AL = extended
scan code (0..0FFh)


ModiFromKey - get modifiers from key code

INPUT:
AX = key code

OUTPUT:
AL = modifiers (0..7), B0=Shift, B1=Ctrl, B2=Alt


ScanModiFromKey - get extended scan code with modifiers from key code

INPUT:
AX = key code

OUTPUT:
AL = extended
scan code (0..0FFh)
AH = modifiers (0..7), B0=Shift, B1=Ctrl, B2=Alt


CharFromKey - get character code from key code

INPUT:
AX = key code

OUTPUT:
AL = character (0..0ffh)


SetTimer2Gate - set Timer 2 gate

INPUT:
AL = Timer 2 gate 1=enable, 0=disable

NOTES: It temporaly disables interrupts. It takes aprox. 3 us.


GetTimer2Out - get Timer 2 output

OUTPUT:
AL = Timer 2 output (0 and CY, 1 and NC)
CY = output is 0 (AL = 0)

NOTES: Output from Timer 2 must be enabled using SetTimer2Gate. It takes aprox. 1.5 us.


SetSpeakerGate - set speaker gate

INPUT:
AL = speaker gate 1=enable, 0=disable

NOTES: It temporaly disables interrupts. It takes aprox. 3 us.


keyboard modifiers:

KEY_MODI_SCROLL: (=B0) Scroll Lock is ON (LED hardcoded)
KEY_MODI_NUM: (=B1) Num Lock is ON (LED hardcoded)
KEY_MODI_CAPS: (=B2) Caps Lock is ON (LED hardcoded)
KEY_MODI_INSERT: (=B3) Insert is ON
KEY_MODI_PAUSE: (=B4) Pause is ON


Language:

LANG_EN: (=0) English
LANG_CZ: (=1) Czech (KEYBCS2)


Key flags:

KEYFLAG_SPEC: (=B15) control or special key flag
KEYFLAG_EXT: (=B7) extended key flag
KEYFLAG_ALT: (=B6) Alt modifier flag
KEYFLAG_CTRL: (=B5) Ctrl modifier flag
KEYFLAG_SHIFT: (=B4) Shift modifier flag
KEYFLAG_MODI: (=B4+B5+B6) modifiers mask
KEYFLAG_TABNUM: (=16) number of table ASCII characters
KEYFLAG_MASK: (=0fh) table ASCII character mask


Keyboard base SCAN codes:

KEY_NONE: (=00h) no key
KEY_ESC: (=01h) Esc
KEY_1: (=02h) 1 !
KEY_2: (=03h) 2 @
KEY_3: (=04h) 3 #
KEY_4: (=05h) 4 $
KEY_5: (=06h) 5 %
KEY_6: (=07h) 6 ^
KEY_7: (=08h) 7 &
KEY_8: (=09h) 8 *
KEY_9: (=0Ah) 9 (
KEY_0: (=0Bh) 0 )
KEY_HYPHEN: (=0Ch) - _
KEY_EQU: (=0Dh) = +
KEY_BS: (=0Eh) BackSpace
KEY_TAB: (=0Fh) Tab
KEY_Q: (=10h) Q
KEY_W: (=11h) W
KEY_E: (=12h) E
KEY_R: (=13h) R
KEY_T: (=14h) T
KEY_Y: (=15h) Y
KEY_U: (=16h) U
KEY_I: (=17h) I
KEY_O: (=18h) O
KEY_P: (=19h) P
KEY_LBRACKET: (=1Ah) [ {
KEY_RBRACKET: (=1Bh) ] }
KEY_ENTER: (=1Ch) Enter
KEY_LCTRL: (=1Dh) Left Ctrl
KEY_CTRL: (=KEY_LCTRL) Ctrl base scan code
KEY_A: (=1Eh) A
KEY_S: (=1Fh) S
KEY_D: (=20h) D
KEY_F: (=21h) F
KEY_G: (=22h) G
KEY_H: (=23h) H
KEY_J: (=24h) J
KEY_K: (=25h) K
KEY_L: (=26h) L
KEY_SEMICOLON: (=27h) ; :
KEY_SQUOTE: (=28h) ' "
KEY_BACKQUOTE: (=29h) ` ~
KEY_LSHIFT: (=2Ah) Left Shift
KEY_BACKSLASH: (=2Bh) \ |
KEY_Z: (=2Ch) Z
KEY_X: (=2Dh) X
KEY_C: (=2Eh) C
KEY_V: (=2Fh) V
KEY_B: (=30h) B
KEY_N: (=31h) N
KEY_M: (=32h) M
KEY_COMMA: (=33h) , <
KEY_PERIOD: (=34h) . >
KEY_SLASH: (=35h) / ?
KEY_RSHIFT: (=36h) Right Shift
KEY_GREYSTAR: (=37h) Gray [*]
KEY_LALT: (=38h) Left Alt
KEY_ALT: (=KEY_LALT) Alt base scan code
KEY_SPACE: (=39h) SpaceBar
KEY_CAPSLOCK: (=3Ah) CapsLock
KEY_F1: (=3Bh) F1
KEY_F2: (=3Ch) F2
KEY_F3: (=3Dh) F3
KEY_F4: (=3Eh) F4
KEY_F5: (=3Fh) F5
KEY_F6: (=40h) F6
KEY_F7: (=41h) F7
KEY_F8: (=42h) F8
KEY_F9: (=43h) F9
KEY_F10: (=44h) F10
KEY_NUMLOCK: (=45h) NumLock
KEY_SCROLL: (=46h) ScrollLock
KEY_NUM7: (=47h) [7 Home]
KEY_NUM8: (=48h) [8 Up]
KEY_NUM9: (=49h) [9 PgUp]
KEY_GREYMINUS: (=4Ah) Gray [-]
KEY_NUM4: (=4Bh) [4 Left]
KEY_NUM5: (=4Ch) [5]
KEY_NUM6: (=4Dh) [6 Right]
KEY_GREYPLUS: (=4Eh) Gray [+]
KEY_NUM1: (=4Fh) [1 End]
KEY_NUM2: (=50h) [2 Down]
KEY_NUM3: (=51h) [3 PgDn]
KEY_NUM0: (=52h) [0 Ins]
KEY_DECIMAL: (=53h) [. Del]
KEY_SYSRQ: (=54h) SysRq (PrtScr with Alt)

KEY_BACKSLASH2 (=56h) \ | alternative
KEY_F11: (=57h) F11
KEY_F12: (=58h) F12

KEY_RESERVEDE0: (=60h) reserved, E0 prefix
KEY_RESERVEDE1: (=61h) reserved, E1 prefix

KEY_RESERVEDEE: (=6Eh) reserved, EE echo

KEY_RESERVEDFA: (=7Ah) reserved, FA acknowledge

KEY_RESERVEDFC: (=7Ch) reserved, FC failure MF
KEY_RESERVEDFD: (=7Dh) reserved, FD failure AT
KEY_RESERVEDFE: (=7Eh) reserved, FE send error NACK
KEY_RESERVEDFF: (=7Fh) reserved, FF error, buffer full

 

Keyboard extended SCAN codes (with E0 prefix):
(Some key send Ext. Left Shift (E0 2A), if Num Lock is ON)

KEY_MESSENGER: (=05h+B7) Messenger

KEY_EDITREDO: (=07h+B7) Edit Redo
KEY_EDITUNDO: (=08h+B7) Edit Undo
KEY_APPLEFT: (=09h+B7) Application Left
KEY_EDITPASTE: (=0Ah+B7) Edit Paste
KEY_SCRLNORM: (=0Bh+B7) Scroll Normal

KEY_MEDPREV: (=10h+B7) Media Previous
KEY_SCRLFAST: (=11h+B7) Scroll Fast
KEY_SCRLFASTER: (=12h+B7) Scroll Faster
KEY_WORD: (=13h+B7) Word
KEY_EXCEL: (=14h+B7) Excel
KEY_CALENDAR: (=15h+B7) Calendar
KEY_LOGOFF: (=16h+B7) Log Off
KEY_EDITCUT: (=17h+B7) Edit Cut
KEY_EDITCOPY: (=18h+B7) Edit Copy
KEY_MEDNEXT: (=19h+B7) Media Next

KEY_GREYENTER: (=1Ch+B7) Gray [Enter]
KEY_RCTRL: (=1Dh+B7) Right Ctrl (or with 0E1h with Pause/Break)
KEY_APPRIGHT: (=1Eh+B7) Application Right
KEY_SCRLFASTEST: (=1Fh+B7) Scroll Fastest
KEY_VOLMUTE: (=20h+B7) Volume Mute
KEY_CALCUL: (=21h+B7) Calculator
KEY_MEDPLAY: (=22h+B7) Media Play
KEY_SPELL: (=23h+B7) Spell, Wheel Press Down
KEY_MEDSTOP: (=24h+B7) Media Stop

KEY_LSHIFT2: (=2Ah+B7) Fake Left Shift (gen. by keyboard, ignored)

KEY_VOLDOWN: (=2Eh+B7) Volume -

KEY_VOLUP: (=30h+B7) Volume +

KEY_WWWHOME: (=32h+B7) WWW Home

KEY_GREYSLASH: (=35h+B7) Gray [/]
KEY_RSHIFT2: (=36h+B7) Fake Right Shift (gen. by keyboard, ignored)
KEY_PRINT: (=37h+B7) PrintScr
KEY_RALT: (=38h+B7) Right Alt

KEY_HELP: (=3Bh+B7) Help
KEY_MYMUSIC: (=3Ch+B7) My Music
KEY_TASK: (=3Dh+B7) Task Pane
KEY_FILENEW: (=3Eh+B7) File New
KEY_FILEOPEN: (=3Fh+B7) File Open
KEY_FILECLOSE: (=40h+B7) File Close
KEY_EMAILREPLY: (=41h+B7) Email Reply
KEY_EMAILFRWRD: (=42h+B7) Email Forward
KEY_EMAILSEND: (=43h+B7) Email Send

KEY_PAUSE: (=45h+B7) Pause/Break (E1 1D 45 E1 9D C5)
KEY_BREAK: (=46h+B7) Break (Pause with Ctrl)
KEY_HOME: (=47h+B7) Home
KEY_UP: (=48h+B7) Up, Wheel Up
KEY_PAGEUP: (=49h+B7) Page Up

KEY_LEFT: (=4Bh+B7) Left

KEY_RIGHT: (=4Dh+B7) Right

KEY_END: (=4Fh+B7) End
KEY_DOWN: (=50h+B7) Down, Wheel Down
KEY_PAGEDOWN: (=51h+B7) Page Down
KEY_INSERT: (=52h+B7) Insert
KEY_DELETE: (=53h+B7) Delete

KEY_FILESAVE: (=57h+B7) File Save
KEY_FILEPRINT: (=58h+B7) File Print

KEY_LWIN: (=5Bh+B7) Left Win
KEY_RWIN: (=5Ch+B7) Right Win
KEY_MENU: (=5Dh+B7) Local Menu
KEY_POWER: (=5Eh+B7) Power
KEY_SLEEP: (=5Fh+B7) Sleep
KEY_RESERVEDXE0: (=60h+B7) reserved, E0 prefix
KEY_RESERVEDXE1: (=61h+B7) reserved, E1 prefix

KEY_WAKEUP: (=63h+B7) Wake Up
KEY_MYPIC: (=64h+B7) My Picture
KEY_FILESEARCH: (=65h+B7) File Search
KEY_WWWFAVOR: (=66h+B7) WWW Favorites
KEY_WWWREFRESH: (=67h+B7) WWW Refresh
KEY_WWWSTOP: (=68h+B7) WWW Stop
KEY_WWWFORWARD: (=69h+B7) WWW Forward
KEY_WWWBACK: (=6Ah+B7) WWW Back
KEY_MYCOMP: (=6Bh+B7) My Computer
KEY_EMAIL: (=6Ch+B7) E-mail
KEY_MEDIA: (=6Dh+B7) Media Select

KEY_RESERVEDXEE: (=6Eh+B7) reserved, EE echo

KEY_RESERVEDXFA: (=7Ah+B7) reserved, FA acknowledge

KEY_RESERVEDXFC: (=7Ch+B7) reserved, FC failure MF
KEY_RESERVEDXFD: (=7Dh+B7) reserved, FD failure AT
KEY_RESERVEDXFE: (=7Eh+B7) reserved, FE send error NACK
KEY_RESERVEDXFF: (=7Fh+B7) reserved, FF error, buffer full


Source code KEY.ASM

<< Back