ReadKey
PROC (Not covered in the 4th
edition)
Performs a no-wait keyboard check and reads a
single character if available.
If the returned ASCII code is zero, special keys
can be processed by checking the virtual scan code (ah) and virtual
key code (dx).
Call args: None.
Return arg: ZF=1 if no key is available,
ZF=0 if a key is read into the following registers:
AL = key's Ascii code (is set to zero for special extended codes)
AH = Virtual scan code
DX = Virtual key code
EBX = Keyboard flags (Alt,Ctrl,Caps,etc.)
Upper halves of EAX and EDX are overwritten.
Example:
INCLUDE Irvine32.inc
INCLUDE Macros.inc
.code
main PROC ; Read and display each key until <Esc> is input.
mWriteLn " ASCII Virtual-scan Virtual-key Keyboard flags"
call Crlf
LookForKey:
mov eax,50 ; sleep, to allow OS to time slice
call Delay ; (otherwise, some key presses are lost)
call ReadKey ; look for keyboard input
jz LookForKey ; no key pressed yet
mShow al,h
mShow ah,h
mShow dx,h
mShow ebx,hnn
cmp dx,VK_ESCAPE ; time to quit?
jne LookForKey ; no, go get next key.
exit
main ENDP
END main
Output when F1, Shift-F1, Ctrl-F1, Alt-F1, and Esc keys are input:
ASCII Virtual-scan Virtual-key Keyboard flags
al = 00h ah = 3Bh dx = 0070h ebx = 00000000h
al = 00h ah = 54h dx = 0070h ebx = 00000010h
al = 00h ah = 5Eh dx = 0070h ebx = 00000004h
al = 00h ah = 68h dx = 0070h ebx = 00000001h
al = 1Bh ah = 01h dx = 001Bh ebx = 00000000h
Notes: To wait for and read a single character from
standard input, use the ReadChar
procedure.
| Converted from CHM to HTML with chm2web Pro 2.85 (unicode) |