The following program tests ReadKey by waiting for a keypress and then reporting whether or not the CapsLock key is down. Note that, you must include a delay factor when calling ReadKey to allow time for MS-Windows to process its message loop:
Table 1: keyboard Control Key State Values.
Value |
Meaning |
CAPSLOCK_ON |
The CAPS LOCK light is on. |
ENHANCED_KEY |
The key is enhanced. |
LEFT_ALT_PRESSED |
The left ALT key is pressed. |
LEFT_CTRL_PRESSED |
The left CTRL key is pressed. |
NUMLOCK_ON |
The NUM LOCK light is on. |
RIGHT_ALT_PRESSED |
The right ALT key is pressed. |
RIGHT_CTRL_PRESSED |
The right CTRL key is pressed. |
SCROLLLOCK_ON |
The SCROLL LOCK light is on. |
SHIFT_PRESSED |
The SHIFT key is pressed. |
TITLE Testing ReadKey (TestReadkey.asm) INCLUDE Irvine32.inc INCLUDE Macros.inc .code main PROC L1: mov eax,10 ; delay for msg processing call Delay call ReadKey ; wait for a keypress jz L1 test ebx,CAPSLOCK_ON jz L2 mWrite <"CapsLock is ON",0dh,0ah> jmp L3 L2: mWrite <"CapsLock is OFF",0dh,0ah> L3: exit main ENDP END main