在用中断16H的0号功能时,当按下任意一个键或组合键时,寄存器AH和AL分别保存着该按键的扫描码和ASCII码。 表1、ASCII码的编码方案
高位
低位
000 001 010 011 100 101 110 111 SOH DC1 ! 1 A Q a q 0000 NUL DEL SP 0 @ P ` p 0001 0010 STX DC2 “ 2 B R b r 0011 ETX DC3 # 3 C S c s 0100 EOT DC4 $ 4 D T d t 0101 ENQ NAK % 5 E U e u 0110 ACK SYN & 6 F V f v 0111 BEL ETB ‘ 7 G W g w 1000 BS CAN ( 8 H X h x 1001 HT EM ) 9 I Y i y 1010 LF SUB * : J Z j z 1011 VT ESC + ; K [ k { 1100 FF FS < L \ l | 1101 CR GS - = M ] m } 1110 SO RS . > N ^ n ~ 1111 SI US / ? O _ o Del
表4、数字键盘的编码表
按键
单键 SHIFT CTRL ALT 扫描码 ASCII码 扫描码 ASCII码 扫描码 ASCII码 扫描码 ASCII码 Ins & 0 52 00 52 30 92 00 End & 1 4F 00 4F 31 75 00 00 01 ↓ & 2 50 00 50 32 91 00 00 02 PgDn & 3 51 00 51 33 76 00 00 03 ← & 4 4B 00 4B 34 73 00 00 04 5 4C 00 4C 35 8F 00 00 05 → & 6 4D 00 4D 36 74 00 00 06 Home & 7 47 00 47 37 77 00 00 07 ↑ & 8 48 00 48 38 8D 00 00 08 PgUp & 9 49 00 49 39 84 00 00 09 + 4E 2B 4E 2B 90 00 4E 00 - 4A 2D 4A 2D 8E 00 4A 00 Del & '.' 53 00 53 2E 93 00 * 37 2A 37 2A 96 00 37 00
表5、第一排数字键盘的编码表
按键 单键 SHIFT CTRL ALT 扫描码 ASCII码 扫描码 ASCII码 扫描码 ASCII码 扫描码 ASCII码 ` and ~ 29 60 29 7E 29 00 1 and ! 02 31 02 21 78 00 2 and @ 03 32 03 40 03 00 79 00 3 and # 04 33 04 23 7A 00 4 and $ 05 34 05 24 7B 00 5 and % 06 35 06 25 7C 00 6 and ^ 07 36 07 5E 07 1E 7D 00 7 and & 08 37 08 26 7E 00 8 and * 09 38 09 2A 7F 00 9 and ( 0A 39 0A 38 80 00 0 and ) 0B 30 0B 29 81 00 - and _ 0C 2D 0C 5F 0C 1F 82 00 = and + 0D 3D 0D 2B 83 00
表6、操作按键的编码表
按键
单键 SHIFT CTRL ALT 扫描码 ASCII码 扫描码 ASCII码 扫描码 ASCII码 扫描码 ASCII码
Esc
01
1B
01
1B
01
1B
01
00
Backspace
0E
08
0E
08
0E
7F
0E
00
Tab
0F
09
0F
00
94
00
A5
00
Enter
1C
0D
1C
0D
1C
0A
1C
00
表7、标号按键的编码表
按键
单键 SHIFT CTRL ALT 扫描码 ASCII码 扫描码 ASCII码 扫描码 ASCII码 扫描码 ASCII码 [ and { 1A 5B 1A 7B 1A 1B 1A 00 ] and } 1B 5D 1B 7D 1B 1D 1B 00 ; and : 27 3B 27 3A 27 ' and " 28 27 28 22 28 \ and | 2b 5C 2b 7C 2B 1C 2b , and < 33 2C 33 3C 33 . and > 34 2E 34 3E 34 / and ? 35 2F 35 3F 35
表8、附加按键的编码表
按键
单键 SHIFT CTRL ALT 扫描码 ASCII码 扫描码 ASCII码 扫描码 ASCII码 扫描码 ASCII码 Slash(/) E0 2F E0 2F 95 00 A4 00 Enter E0 0D E0 0D E0 0A A6 00 Home 47 E0 47 E0 77 E0 97 00 End 4F E0 4F E0 75 E0 9F 00 PageUp 49 E0 49 E0 84 E0 99 00 PageDown 51 E0 51 E0 76 E0 A1 00 DnArrow 50 E0 50 E0 91 E0 A0 00 LeftArrow 4B E0 4B E0 73 E0 9B 00 RightArrow 4D E0 4D E0 74 E0 9D 00 UpArrow 48 E0 48 E0 8D E0 98 00 Ins 52 E0 52 E0 92 E0 A2 00 Del 53 E0 53 E0 93 E0 A3 00
表9、其它按键的扫描码
当这些键被按下时,BIOS并没有把它们的扫描码输入键盘缓冲区。
按键
扫描码
CapsLock
3A
NumLock
45
ScrollLock
46
Shift(Left)
2A
Shift(Right)
36
Alt
38
Ctrl
1D
PrtScreen
37
Up Sleep Power
Ins210 Home199 PgUp201 Num197 /181 *55 -74 Del211 End207 PgDn209 771 872 973 +78 475 576 677 ↑200 179 280 381 Enter156 ←203 ↓208 →205 082 .83 这里罗列了键盘上各键的扫描码,还有ALT、CTR、SHIFT与部分键的组合扫描码。这对于编写需要键盘处理的程序应该有所帮助!
#define KEY_L1 0x4F
#define KEY_L2 0x50
#define KEY_L3 0x51
#define KEY_L4 0x4B
#define KEY_L6 0x4D
#define KEY_L7 0x47
#define KEY_L8 0x48
#define KEY_L9 0x49
#define KEY_ADD 0x2B
#define KEY_SUB 0x2D
#define KEY_LEFT 75
#define KEY_RIGHT 77
#define KEY_UP 72
#define KEY_DOWN 80
#define KEY_F1 59
#define KEY_F2 60
#define KEY_F3 61
#define KEY_F4 62
#define KEY_F5 63
#define KEY_F6 64
#define KEY_F7 65
#define KEY_F8 66
#define KEY_F9 67
#define KEY_F10 68
#define KEY_INSERT 82
#define KEY_HOME 71
#define KEY_PAGEUP 73
#define KEY_PAGEDOWN 81
#define KEY_DEL 83
#define KEY_END 79
#define KEY_DASH 12
#define KEY_EQUAL 13
#define KEY_LBRACKET 26
#define KEY_RBRACKET 27
#define KEY_SEMICOLON 39
#define KEY_RQUOTE 40
#define KEY_LQUOTE 41
#define KEY_PERIOD 52
#define KEY_COMMA 51
#define KEY_SLASH 53
#define KEY_BACKSLASH 43
#define KEY_ENTER 28
#define KEY_BACKSPACE 14
#define KEY_SPACE 57
#define KEY_TAB 15
#define KEY_ESC 1
#define KEY_Q 16
#define KEY_W 17
#define KEY_E 18
#define KEY_R 19
#define KEY_T 20
#define KEY_Y 21
#define KEY_U 22
#define KEY_I 23
#define KEY_O 24
#define KEY_P 25
#define KEY_A 30
#define KEY_S 31
#define KEY_D 32
#define KEY_F 33
#define KEY_G 34
#define KEY_H 35
#define KEY_J 36
#define KEY_K 37
#define KEY_L 38
#define KEY_Z 44
#define KEY_X 45
#define KEY_C 46
#define KEY_V 47
#define KEY_B 48
#define KEY_N 49
#define KEY_M 50
#define KEY_1 2
#define KEY_2 3
#define KEY_3 4
#define KEY_4 5
#define KEY_5 6
#define KEY_6 7
#define KEY_7 8
#define KEY_8 9
#define KEY_9 10
#define KEY_0 11
/+++++++++++++++++++++++++CTR+各键扫描码+++++++++++++++++++++++++/
#define KEY_F1 0x5E
#define KEY_F2 0x5F
#define KEY_F3 0x60
#define KEY_F4 0x61
#define KEY_F5 0x62
#define KEY_F6 0x63
#define KEY_F7 0x64
#define KEY_F8 0x65
#define KEY_F9 0x66
#define KEY_F10 0x67
#define KEY_2 0x03
#define KEY_6 0x1E
#define KEY_Q 0x11
#define KEY_W 0x17
#define KEY_E 0x05
#define KEY_R 0x12
#define KEY_T 0x14
#define KEY_Y 0x19
#define KEY_U 0x15
#define KEY_I 0x09
#define KEY_O 0x0F
#define KEY_P 0x10
#define KEY_LBRACKET 0x1B
#define KEY_RBRACKET 0x1D
#define KEY_A 0x01
#define KEY_S 0x13
#define KEY_D 0x04
#define KEY_F 0x06
#define KEY_G 0x07
#define KEY_H 0x08
#define KEY_J 0x0A
#define KEY_K 0x0B
#define KEY_L 0x0C
#define KEY_Z 0x1A
#define KEY_X 0x18
#define KEY_C 0x03
#define KEY_V 0x16
#define KEY_B 0x02
#define KEY_N 0x0E
#define KEY_M 0x0D
#define KEY_SPACE 0x20
#define KEY_BACKSPACE 0x7F
#define KEY_ENTER 0x0A
#define KEY_BACKSLASH 0x1C
#define KEY_L1 0x75
#define KEY_L3 0x76
#define KEY_L4 0x73
#define KEY_L6 0x74
#define KEY_L7 0x77
#define KEY_L9 0x84
/+++++++++++++++++++++++++SHIFT+各键扫描码+++++++++++++++++++++++++/
#define KEY_LQUOTE 0x7E
#define KEY_1 0x21
#define KEY_2 0x40
#define KEY_3 0x23
#define KEY_4 0x24
#define KEY_5 0x25
#define KEY_6 0x5E
#define KEY_7 0x26
#define KEY_8 0x2A
#define KEY_9 0x28
#define KEY_0 0x29
#define KEY_DASH 0x5F
#define KEY_EQUAL 0x2B
#define KEY_BACKSPACE 0x08
#define KEY_Q 0x51
#define KEY_W 0x57
#define KEY_E 0x45
#define KEY_R 0x52
#define KEY_T 0x54
#define KEY_Y 0x59
#define KEY_U 0x55
#define KEY_I 0x49
#define KEY_O 0x4F
#define KEY_P 0x50
#define KEY_LBRACKET 0x7B
#define KEY_RBRACKET 0x7D
#define KEY_ENTER 0x0D
#define KEY_A 0x41
#define KEY_S 0x53
#define KEY_D 0x44
#define KEY_F 0x46
#define KEY_G 0x47
#define KEY_H 0x48
#define KEY_J 0x4A
==================================================================================================
键盘键与虚拟键码对照表
字母和数字键 数字小键盘的键 功能键 其它键
键 键码键 键码 键 键码 键键码
A65 0 96 F1 112 Backspace 8
B66 1 97 F2 113 Tab 9
C67 2 98 F3 114 Clear 12
D68 3 99 F4 115 Enter 13
E69 4 100F5 116 Shift 16
F70 5 101F6 117 Control 17
G71 6 102F7 118 Alt 18
H72 7 103F8 119 Caps Lock 20
I73 8 104F9 120 Esc 27
J74 9 105F10121 Spacebar32
K75 * 106F11122 Page Up 33
L76 + 107F12123 Page Down 34
M77 Enter 108-- --End 35
N78 - 109-- -- Home36
O79 . 110-- -- Left Arrow37
P80 / 111-- -- Up Arrow38
Q81 -- ---- -- Right Arrow 39
R82 -- ---- -- Down Arrow 40
S83 -- ---- -- Insert 45
T84 -- ---- -- Delete 46
U85 -- ---- -- Help 47
V86 -- ---- -- Num Lock 144
W87
X88
Y89
Z90
048
149
250
351
452
553
654
755
856
957
0x1 鼠标左键
0x2 鼠标右键
0x3 CANCEL 键
0x4 鼠标中键
0x8 BACKSPACE 键
0x9 TAB 键
0xC CLEAR 键
0xD ENTER 键
0x10 SHIFT 键
0x11 CTRL 键
0x12 MENU 键
0x13 PAUSE 键
0x14 CAPS LOCK 键
0x1B ESC 键
0x20 SPACEBAR 键
0x21 PAGE UP 键
0x22 PAGE DOWN 键
0x23 END 键
0x24 HOME 键
0x25 LEFT ARROW 键
0x26 UP ARROW 键
0x27 RIGHT ARROW 键
0x28 DOWN ARROW 键
0x29 Select 键
0x2A PRINT SCREEN 键
0x2B EXECUTE 键
0x2C SNAPSHOT 键
0x2D Insert 键
0x2E Delete 键
0x2F HELP 键
0x90 NUM LOCK 键
A 至 Z 键与 A – Z 字母的 ASCII 码相同:
值 描述
65 A 键
66 B 键
67 C 键
68 D 键
69 E 键
70 F 键
71 G 键
72 H 键
73 I 键
74 J 键
75 K 键
76 L 键
77 M 键
78 N 键
79 O 键
80 P 键
81 Q 键
82 R 键
83 S 键
84 T 键
85 U 键
86 V 键
87 W 键
88 X 键
89 Y 键
90 Z 键
0 至 9 键与数字 0 – 9 的 ASCII 码相同:
值 描述
48 0 键
49 1 键
50 2 键
51 3 键
52 4 键
53 5 键
54 6 键
55 7 键
56 8 键
57 9 键
下列常数代表数字键盘上的键:
值 描述
0x60 0 键
0x61 1 键
0x62 2 键
0x63 3 键
0x64 4 键
0x65 5 键
0x66 6 键
0x67 7 键
0x68 8 键
0x69 9 键
0x6A MULTIPLICATION SIGN (*) 键
0x6B PLUS SIGN (+) 键
0x6C ENTER 键
0x6D MINUS SIGN (–) 键
0x6E DECIMAL POINT (.) 键
0x6F DIVISION SIGN (/) 键
下列常数代表功能键:
值 描述
0x70 F1 键
0x71 F2 键
0x72 F3 键
0x73 F4 键
0x74 F5 键
0x75 F6 键
0x76 F7 键
0x77 F8 键
0x78 F9 键
0x79 F10 键
0x7A F11 键
0x7B F12 键
0x7C F13 键
0x7D F14 键
0x7E F15 键
0x7F F16 键
0 None
3 Cancel(Break)
8 Back
9 Tab
13 Return
16 ShiftKey
17 ControlKey
18 Menu
19 Pause
20 Capital(大小写)
27 Escape
32 Space
33 PageUp
34 Next(PageDonw)
35 End
36 Home
37 Left
38 Up
39 Right
40 Down
0-9 48-57
45 Insert
46 Delete
65->90 A->Z
91 LWin
93 Apps
96 105 NumPad0-
106 Multiply *
107 Add+
108
109 Subtract-
110 Decimal .
111 Divide /
112-123 F1-F12
144 NumLock
145 Scroll
173 VolumeMute
174 VolumeDown
175 VolumeUp
186 Oem1 ;
187 Oemplus =
188 Oemcomma ,
189 OemMinus -
190 OemPeriod .
191 OemQuestion /
192 Oemtilde `
219 OemOpenBrackets [
220 Oem5 \
221 Oem6 ]
222 Oem7 '