Scan Code Program |
Top Previous Next |
Here is a simple program that illustrates the use of the GetScanCode intrinsic, and it also enables you to test which key codes are available to your programs. Simply copy and paste the program into EXPL.
inc C:\CXPL\EXPLCodes.xpl; \intrinsic declarations
procedure ByteOut(B); int B; int Nibbles; begin Nibbles:=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"]; B:=B & $FF; Text(0,Nibbles(B >> 4)); Text(0,Nibbles(B & $F)); end;
procedure WordOut(W); int W; begin W:=W & $FFFF; ByteOut(W >> 8); ByteOut(W & $FF); end;
def VK_LBUTTON = $01, \Left mouse button VK_RBUTTON = $02, \Right mouse button VK_CANCEL = $03, \Control+Break VK_MBUTTON = $04, \Middle mouse button VK_BACK = $08, \Backspace key VK_TAB = $09, \Tab key VK_CLEAR = $0C, \Clear key VK_RETURN = $0D, \Enter key VK_LSHIFT = $10, \Shift key VK_CONTROL = $11, \Ctrl key VK_MENU = $12, \Alt key VK_PAUSE = $13, \Pause key VK_CAPITAL = $14, \Caps Lock key VK_KANA = $15, \Used with IME VK_HANGUL = $15, \Used with IME VK_JUNJA = $17, \Used with IME VK_FINAL = $18, \Used with IME VK_HANJA = $19, \Used with IME VK_KANJI = $19, \Used with IME VK_CONVERT = $1C, \Used with IME VK_NONCONVERT = $1D, \Used with IME VK_ACCEPT = $1E, \Used with IME VK_MODECHANGE = $1F, \Used with IME VK_ESCAPE = $1B, \Esc key VK_SPACE = $20, \Space bar VK_PRIOR = $21, \Page Up key VK_NEXT = $22, \Page Down key VK_END = $23, \End key VK_HOME = $24, \Home key VK_LEFT = $25, \Left Arrow key VK_UP = $26, \Up Arrow key VK_RIGHT = $27, \Right Arrow key VK_DOWN = $28, \Down Arrow key VK_SELECT = $29, \Select key VK_PRINT = $2A, \Print key (keyboard-specific) VK_EXECUTE = $2B, \Execute key VK_SNAPSHOT = $2C, \Print Screen key VK_INSERT = $2D, \Insert key VK_DELETE = $2E, \Delete key VK_HELP = $2F, \Help key \ VK_ thru VK_9 are the same as ASCII '0' thru '9' ($30 - $39) VK_0 = $30, VK_1 = $31, VK_2 = $32, VK_3 = $33, VK_4 = $34, VK_5 = $35, VK_6 = $36, VK_7 = $37, VK_8 = $38, VK_9 = $39, \ VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' ($41 - $5A) VK_A = $41, VK_B = $42, VK_C = $43, VK_D = $44, VK_E = $45, VK_F = $46, VK_G = $47, VK_H = $48, VK_I = $49, VK_J = $4A, VK_K = $4B, VK_L = $4C, VK_M = $4D, VK_N = $4E, VK_O = $4F, VK_P = $50, VK_Q = $51, VK_R = $52, VK_S = $53, VK_T = $54, VK_U = $55, VK_V = $56, VK_W = $57, VK_X = $58, VK_Y = $59, VK_Z = $5A, VK_LWIN = $5B, \Left Windows key (Microsoft keyboard) VK_RWIN = $5C, \Right Windows key (Microsoft keyboard) VK_APPS = $5D, \Applications key (Microsoft keyboard) VK_NUMPAD0 = $60, \0 key (numeric keypad) VK_NUMPAD1 = $61, \1 key (numeric keypad) VK_NUMPAD2 = $62, \2 key (numeric keypad) VK_NUMPAD3 = $63, \3 key (numeric keypad) VK_NUMPAD4 = $64, \4 key (numeric keypad) VK_NUMPAD5 = $65, \5 key (numeric keypad) VK_NUMPAD6 = $66, \6 key (numeric keypad) VK_NUMPAD7 = $67, \7 key (numeric keypad) VK_NUMPAD8 = $68, \8 key (numeric keypad) VK_NUMPAD9 = $69, \9 key (numeric keypad) VK_MULTIPLY = $6A, \Multiply key (numeric keypad) VK_ADD = $6B, \y (numeric keypad) VK_SEPARATOR = $6C, \Separator key (numeric keypad) VK_SUBTRACT = $6D, \Subtract key (numeric keypad) VK_DECIMAL = $6E, \Decimal key (numeric keypad) VK_DIVIDE = $6F, \Divide key (numeric keypad) VK_F1 = $70, \F1 key VK_F2 = $71, \F2 key VK_F3 = $72, \F3 key VK_F4 = $73, \F4 key VK_F5 = $74, \F5 key VK_F6 = $75, \F6 key VK_F7 = $76, \F7 key VK_F8 = $77, \F8 key VK_F9 = $78, \F9 key VK_F10 = $79, \F10 key VK_F11 = $7A, \F11 key VK_F12 = $7B, \F12 key VK_F13 = $7C, \F13 key VK_F14 = $7D, \F14 key VK_F15 = $7E, \F15 key VK_F16 = $7F, \F16 key VK_F17 = $80, \F17 key VK_F18 = $81, \F18 key VK_F19 = $82, \F19 key VK_F20 = $83, \F20 key VK_F21 = $84, \F21 key VK_F22 = $85, \F22 key VK_F23 = $86, \F23 key VK_F24 = $87, \F24 key VK_NUMLOCK = $90, \Num Lock key VK_SCROLL = $91, \Scroll Lock key VK_PROCESSKEY = $E5, \Process key VK_ATTN = $F6, \Attn key VK_CRSEL = $F7, \CrSel key VK_EXSEL = $F8, \ExSel key VK_EREOF = $F9, \Erase EOF key VK_PLAY = $FA, \Play key VK_ZOOM = $FB, \Zoom key VK_NONAME = $FC, \Reserved for future use VK_PA1 = $FD, \PA1 key VK_OEM_CLEAR = $FE; \Clear key
procedure DecodeScanCode(C); int C; char S; begin case C of $0001 : S:="Esc"; $0002 : S:="! 1"; $0003 : S:="@ 2"; $0004 : S:="# 3"; $0005 : S:="$0004 "; $0006 : S:="5%"; $0007 : S:="^ 6"; $0008 : S:="& 7"; $0009 : S:="* 8"; $000A: S:="( 9"; $000B: S:=") 0"; $000C: S:="_ -"; $000D: S:="+ ="; $000E: S:="Back Space"; $000F: S:="Tab"; $0010: S:="Q"; $0011: S:="W"; $0012: S:="E"; $0013: S:="R"; $0014: S:="T"; $0015: S:="Y"; $0016: S:="U"; $0017: S:="I"; $0018: S:="O"; $0019: S:="P"; $001A: S:="{ ["; $001B: S:="} ]"; $001C: S:="Enter"; $001D: S:="Ctrl L"; $001E: S:="A"; $001F: S:="S"; $0020 : S:="D"; $0021 : S:="F"; $0022 : S:="G"; $0023 : S:="H"; $0024 : S:="J"; $0025 : S:="K"; $0026 : S:="L"; $0027 : S:=": ;"; $0028 : S:="Quotes"; $0029 : S:="~ `"; $002A: S:="Shift Left"; $002B: S:="| \"; $002C: S:="Z"; $002D: S:="X"; $002E: S:="C"; $002F: S:="V"; $0030: S:="B"; $0031: S:="N"; $0032: S:="M"; $0033: S:="< ,"; $0034: S:="> ."; $0035: S:="? /"; $0036: S:="Shift Right"; $0037: S:="* (Keypad)"; $0037: S:="Print Screen"; $0038: S:="Alt Left"; $0039: S:="Space"; $003A: S:="Caps Lock"; $003B: S:="F1"; $003C: S:="F2"; $003D: S:="F3"; $003E: S:="F4"; $003F: S:="F5"; $0040 : S:="F6"; $0041 : S:="F7"; $0042 : S:="F8"; $0043 : S:="F9"; $0044 : S:="F10"; $0045 : S:="Pause Breakk"; $0046 : S:="Scroll Lock"; $0047 : S:="7-Home (Keypad)"; $0048 : S:="8 Up Arrow (Keypad)"; $0049 : S:="9 Page Up (Keypad)"; $004A: S:="- (Keypad)"; $004B: S:="4 Left Arrow (Keypad)"; $004C: S:="5 (Keypad)"; $004D: S:="6 Right Arrow (Keypad)"; $004E: S:="+ (Keypad)"; $004F: S:="1 End (Keypad)"; $0050: S:="2 Down Arrow (Keypad)"; $0051: S:="3 PgDn (Keypad)"; $0052: S:="0 Ins (Keypad)"; $0053: S:=". Del (Keypad)"; $0054: S:="Sys Request"; $0057: S:="F11"; $0058: S:="F12"; $005B: S:="F13"; $005C: S:="F14"; $005D: S:="F15"; $0063 : S:="F16"; $0064 : S:="F17"; $0065 : S:="F18"; $0066 : S:="F19"; $0067 : S:="F20"; $0068 : S:="F21"; $0069 : S:="F22"; $006A: S:="F23"; $006B: S:="F24"; $0138 : S:="Alt Right"; $0145: S:="Num Lock"; $0147: S:="Home"; $0148 : S:="Up Arrow"; $0149 : S:="Page Up"; $014B: S:="Left Arrow"; $014D: S:="Right Arrow"; $014F: S:="End"; $0150: S:="Down Arrow"; $0151: S:="Page Down"; $0152: S:="Ins"; $0153: S:="Del"; $015B: S:="Win Left"; $015C: S:="Win Right"; $015D: S:="Win Menu" other S:="Unkown"; Text(0,S); end;
procedure DecodeVirtualCode(C); int C; char S; begin case C of VK_LBUTTON: S:="LBUTTON"; VK_RBUTTON: S:="RBUTTON"; VK_CANCEL: S:="CANCEL"; VK_MBUTTON: S:="MBUTTON"; VK_BACK: S:="BACK"; VK_TAB: S:="TAB"; VK_CLEAR: S:="CLEAR"; VK_RETURN: S:="RETURN"; VK_LSHIFT: S:="LSHIFT"; VK_CONTROL: S:="CONTROL"; VK_MENU: S:="MENU"; VK_PAUSE: S:="PAUSE"; VK_CAPITAL: S:="CAPITAL"; VK_KANA: S:="KANA"; VK_HANGUL: S:="HANGUL"; VK_JUNJA: S:="JUNJA"; VK_FINAL: S:="FINAL"; VK_HANJA: S:="HANJA"; VK_KANJI: S:="KANJI"; VK_CONVERT: S:="CONVERT"; VK_NONCONVERT: S:="NONCONVERT"; VK_ACCEPT: S:="ACCEPT"; VK_MODECHANGE: S:="MODECHANGE"; VK_ESCAPE: S:="ESCAPE"; VK_SPACE: S:="SPACE"; VK_PRIOR: S:="PRIOR"; VK_NEXT: S:="NEXT"; VK_END: S:="END"; VK_HOME: S:="HOME"; VK_LEFT: S:="LEFT"; VK_UP: S:="UP"; VK_RIGHT: S:="RIGHT"; VK_DOWN: S:="DOWN"; VK_SELECT: S:="SELECT"; VK_PRINT: S:="PRINT"; VK_EXECUTE: S:="EXECUTE"; VK_SNAPSHOT: S:="SNAPSHOT"; VK_INSERT: S:="INSERT"; VK_DELETE: S:="DELETE"; VK_HELP: S:="HELP"; VK_0: S:="0-Key"; VK_1: S:="1-Key"; VK_2: S:="2-Key"; VK_3: S:="3-Key"; VK_4: S:="4-Key"; VK_5: S:="5-Key"; VK_6: S:="6-Key"; VK_7: S:="7-Key"; VK_8: S:="8-Key"; VK_9: S:="9-Key"; VK_A: S:="A-Key"; VK_B: S:="B-Key"; VK_C: S:="C-Key"; VK_D: S:="D-Key"; VK_E: S:="E-Key"; VK_F: S:="F-Key"; VK_G: S:="G-Key"; VK_H: S:="H-Key"; VK_I: S:="I-Key"; VK_J: S:="J-Key"; VK_K: S:="K-Key"; VK_L: S:="L-Key"; VK_M: S:="M-Key"; VK_N: S:="N-Key"; VK_O: S:="O-Key"; VK_P: S:="P-Key"; VK_Q: S:="Q-Key"; VK_R: S:="R-Key"; VK_S: S:="S-Key"; VK_T: S:="T-Key"; VK_U: S:="U-Key"; VK_V: S:="V-Key"; VK_W: S:="W-Key"; VK_X: S:="X-Key"; VK_Y: S:="Y-Key"; VK_Z: S:="Z-Key"; VK_LWIN: S:="LWIN"; VK_RWIN: S:="RWIN"; VK_APPS: S:="APPS"; VK_NUMPAD0: S:="NUMPAD0"; VK_NUMPAD1: S:="NUMPAD1"; VK_NUMPAD2: S:="NUMPAD2"; VK_NUMPAD3: S:="NUMPAD3"; VK_NUMPAD4: S:="NUMPAD4"; VK_NUMPAD5: S:="NUMPAD5"; VK_NUMPAD6: S:="NUMPAD6"; VK_NUMPAD7: S:="NUMPAD7"; VK_NUMPAD8: S:="NUMPAD8"; VK_NUMPAD9: S:="NUMPAD9"; VK_MULTIPLY: S:="MULTIPLY"; VK_ADD: S:="ADD"; VK_SEPARATOR: S:="SEPARATOR"; VK_SUBTRACT: S:="SUBTRACT"; VK_DECIMAL: S:="DECIMAL"; VK_DIVIDE: S:="DIVIDE"; VK_F1: S:="F1"; VK_F2: S:="F2"; VK_F3: S:="F3"; VK_F4: S:="F4"; VK_F5: S:="F5"; VK_F6: S:="F6"; VK_F7: S:="F7"; VK_F8: S:="F8"; VK_F9: S:="F9"; VK_F10: S:="F10"; VK_F11: S:="F11"; VK_F12: S:="F12"; VK_F13: S:="F13"; VK_F14: S:="F14"; VK_F15: S:="F15"; VK_F16: S:="F16"; VK_F17: S:="F17"; VK_F18: S:="F18"; VK_F19: S:="F19"; VK_F20: S:="F20"; VK_F21: S:="F21"; VK_F22: S:="F22"; VK_F23: S:="F23"; VK_F24: S:="F24"; VK_NUMLOCK: S:="NUMLOCK"; VK_SCROLL: S:="SCROLL"; VK_PROCESSKEY: S:="PROCESSKEY"; VK_ATTN: S:="ATTN"; VK_CRSEL: S:="CRSEL"; VK_EXSEL: S:="EXSEL"; VK_EREOF: S:="EREOF"; VK_PLAY: S:="PLAY"; VK_ZOOM: S:="ZOOM"; VK_NONAME: S:="NONAME"; VK_PA1: S:="PA1"; VK_OEM_CLEAR: S:="OEM_CLEAR" other S:="Unkown"; Text(0,S); end;
int RawCode,VirtCode,BIOSCode;
begin loop begin GetScanCode(@RawCode,@VirtCode,@BIOSCode, true); Cursor(0,0); Text(0,"Raw: "); WordOut(RawCode); Text(0," "); DecodeScancode(RawCode); Text(0," "); CRLF(0); Text(0,"Virtual:"); WordOut(VirtCode); Text(0," "); DecodeVirtualCode(VirtCode); Text(0," "); CRLF(0); Text(0,"BIOS:"); ByteOut(BIOSCode>>8); Text(0," "); ByteOut(BIOSCode&$FF); Text(0," "); CRLF(0);
end; end; |