ID Number: Q80782
5.00
MS-DOS
Summary:
This article contains a scan code table and sample code that can be
used by an application to look up an ASCII character's associated scan
code.
More Information:
MS-DOS has no function that will return a character's scan code;
however, if you are getting keyboard input from a user, a character's
associated scan code is part of the information returned from ROM-BIOS
Int 16h, function 0 or 10h. Consult the ROM-BIOS function summary for
details on this.
On the other hand, if your application just needs to find a scan code
for an ASCII character, it is necessary to supply a translation table
that contains the scan codes, which can be accessed by the application
as a look-up table based on the ASCII character used as an index.
The following is such a scan code table and a short code sample that
shows how to perform the look-up, based on the character's ASCII
value:
TITLE TEST SCAN CODE TABLE
page 60,128
DOSSEG
.MODEL SMALL
.DATA
EVEN
; SCAN CODES LOOKUP TABLE FOR ASCII CHARACTERS DECIMAL 0 - 127
SCAN_TABLE
; NULL ^A ^B ^C ^D ^E ^F ^G BS TAB ^J ^K ^L CR
DB 00H,1EH,30H,2EH,20H,12H,21H,22H,0EH,0FH,24H,25H,26H,1CH
; ^N ^O ^P ^Q ^R ^S ^T ^U ^V ^W ^X ^Y ^Z ESC
DB 31H,18H,19H,10H,13H,1FH,14H,16H,2FH,11H,2DH,15H,2CH,01H
; ^\ ^] ^^ ^_
DB 2BH,1BH,07H,0CH
; ' ' ! " # $ % & ' ( ) * + , - . /
DB 39H,02H,28H,04H,05H,06H,08H,28H,0AH,0BH,09H,0DH,33H,0CH,34H,35H
; 0 1 2 3 4 5 6 7 8 9
DB 0BH,02H,03H,04H,05H,06H,07H,08H,09H,0AH
; : ; < = > ? @
DB 27H,27H,33H,0DH,34H,35H,03H
; A B C D E F G H I J K L M N O P
DB 1EH,30H,2EH,20H,12H,21H,22H,23H,17H,24H,25H,26H,32H,31H,18H,19H
; Q R S T U V W X Y Z
DB 10H,13H,1FH,14H,16H,2FH,11H,2DH,15H,2CH
; [ \ ] ^ _ `
DB 1AH,2BH,1BH,07H,0CH,29H
; a b c d e f g h i j k l m n o p
DB 1EH,30H,2EH,20H,12H,21H,22H,23H,17H,24H,25H,26H,32H,31H,18H,19H
; q r s t u v w x y z
DB 10H,13H,1FH,14H,16H,2FH,11H,2DH,15H,2CH
; { | } ~
DB 1AH,2BH,1BH,29H
.CODE
START: jmp START_TEST
START_TEST:
mov ax,@DATA
mov ds,ax
;find scan code for 'z'
mov al,'z'
call get_scan
;term test
mov ax,4c00h
int 21h
GET_SCAN PROC NEAR
;On entry: AL has character to look up in scan code table.
;On exit : AH has character's scan code.
mov bx,offset scan_table
xlatb
mov ah,al ;scan value to AH
ret
GET_SCAN ENDP
END START