DXInput中键码的转换(VB6.0代码)

帮朋友做了一个利用DXInput来做的键盘HOOK,但是发现DXInput的DX系列键值与ASCII对不上号.....

想来想去,也只有自己做个表来查了,但是不死心,想想应该还是会有人做这个体力活的吧......于是搜啊搜....

没想到还真找到个,虽然不是很全,哇哈哈,不过正好我要的也就是这些了,收藏一下:

Public Function defineDItoAscii()
'http://www.xtremevbtalk.com/archive/index.php/t-94359.html
'This function will setup an existing array called DItoAscii
'(declared earlier like this: Dim DItoAscii(1 to 211) as Byte).
'Each array location represents a Direct Input keypress code thingy.
'We set each of these locations to its corresponding Ascii value.
'For example, if I press 'M' on the keyboard, Direct Input gives
'me a number 50. But in Ascii, 'M' is represented by 77. So we
'will define our array element 50 as 77. This will, in effect
'change our Direct Input number into its Ascii equivalent.

'Please note that these were all hand selected by visually looking
'at an Ascii chart. For your own unique purposes, you may disagree
'with some of the choices and need to make changes. For example,
'you may wish to convert Direct Input 50 to 'm' (Ascii 109) instead
'of 'M' (Ascii 77).

'Zeros (Ascii for 'NULL) have been assigned to all Direct Input
'values which I either did not understand and/or did not care
'about using.

'As a guideline for making this function I used a mapping of the DIs
'available at: 'http://visualbasicforum.com/showthread.php?t=94359'

'I also used an ascii chart available at www.asciitable.com

'This was written and released 1/2/2004

Dim X As Integer

DItoAscii(1) = 27 'Escape DIK_ESCAPE = 1
DItoAscii(2) = 49 '1 DIK_1 = 2
DItoAscii(3) = 50 '2 DIK_2 = 3
DItoAscii(4) = 51 '3 DIK_3 = 4
DItoAscii(5) = 52 '4 DIK_4 = 5
DItoAscii(6) = 53 '5 DIK_5 = 6
DItoAscii(7) = 54 '6 DIK_6 = 7
DItoAscii(8) = 55 '7 DIK_7 = 8
DItoAscii(9) = 56 '8 DIK_8 = 9
DItoAscii(10) = 57 '9 DIK_9 = 10
DItoAscii(11) = 48 '0 DIK_0 = 11
DItoAscii(12) = 45 '- DIK_MINUS = 12
DItoAscii(13) = 61 '= DIK_EQUALS = 13
DItoAscii(14) = 8 'Backspace DIK_BACKSPACE = 14
DItoAscii(15) = 9 'Tab DIK_TAB = 15
DItoAscii(16) = 81 'Q DIK_Q = 16
DItoAscii(17) = 87 'W DIK_W = 17
DItoAscii(18) = 69 'E DIK_E = 18
DItoAscii(19) = 82 'R DIK_R = 19
DItoAscii(20) = 84 'T DIK_T = 20
DItoAscii(21) = 89 'Y DIK_Y = 21
DItoAscii(22) = 85 'U DIK_U = 22
DItoAscii(23) = 73 'I DIK_I = 23
DItoAscii(24) = 79 'O DIK_O = 24
DItoAscii(25) = 80 'P DIK_P = 25
DItoAscii(26) = 91 '[ DIK_LBRACKET = 26
DItoAscii(27) = 93 '] DIK_RBRACKET = 27
DItoAscii(28) = 13 'Enter DIK_RETURN = 28
DItoAscii(29) = 0 'Caps Lock DIK_LCONTROL = 29 'Define ones I'm not sure about or will not use as 0 (null)
DItoAscii(30) = 65 'A DIK_A = 30
DItoAscii(31) = 83 'S DIK_S = 31
DItoAscii(32) = 68 'D DIK_D = 32
DItoAscii(33) = 70 'F DIK_F = 33
DItoAscii(34) = 71 'G DIK_G = 34
DItoAscii(35) = 72 'H DIK_H = 35
DItoAscii(36) = 74 'J DIK_J = 36
DItoAscii(37) = 75 'K DIK_K = 37
DItoAscii(38) = 76 'L DIK_L = 38
DItoAscii(39) = 59 '; DIK_SEMICOLON = 39
DItoAscii(40) = 39 '' DIK_APOSTROPHE = 40
DItoAscii(41) = 0 '??? DIK_GRAVE = 41 'Define ones I'm not sure about or will not use as 0 (null)
DItoAscii(42) = 15 'Shift DIK_LSHIFT = 42
DItoAscii(43) = 92 '\ DIK_BACKSLASH = 43
DItoAscii(44) = 90 'Z DIK_Z = 44
DItoAscii(45) = 88 'X DIK_X = 45
DItoAscii(46) = 67 'C DIK_C = 46
DItoAscii(47) = 86 'V DIK_V = 47
DItoAscii(48) = 66 'B DIK_B = 48
DItoAscii(49) = 78 'N DIK_N = 49
DItoAscii(50) = 77 'M DIK_M = 50
DItoAscii(51) = 44 ', DIK_COMMA = 51
DItoAscii(52) = 46 '. DIK_PERIOD = 52
DItoAscii(53) = 47 '/ DIK_SLASH = 53
DItoAscii(54) = 15 'Shift DIK_RSHIFT = 54
DItoAscii(55) = 42 '* DIK_MULTIPLY = 55
DItoAscii(56) = 0 'Alt DIK_LALT = 56
DItoAscii(57) = 32 'Space DIK_SPACE = 57
DItoAscii(58) = 0 'Caps Lock DIK_CAPSLOCK = 58 'Define ones I'm not sure about or will not use as 0 (null)
DItoAscii(59) = 0 'F1 DIK_F1 = 59
DItoAscii(60) = 0 'F2 DIK_F2 = 60
DItoAscii(61) = 0 'F3 DIK_F3 = 61
DItoAscii(62) = 0 'F4 DIK_F4 = 62
DItoAscii(63) = 0 'F5 DIK_F5 = 63
DItoAscii(64) = 0 'F6 DIK_F6 = 64
DItoAscii(65) = 0 'F7 DIK_F7 = 65
DItoAscii(66) = 0 'F8 DIK_F8 = 66
DItoAscii(67) = 0 'F9 DIK_F9 = 67
DItoAscii(68) = 0 'F10 DIK_F10 = 68
DItoAscii(69) = 0 'Number Lock DIK_NUMLOCK = 69
DItoAscii(70) = 0 'Scroll Lock DIK_SCROLL = 70
DItoAscii(71) = 55 '7 DIK_NUMPAD7 = 71
DItoAscii(72) = 56 '8 DIK_NUMPAD8 = 72
DItoAscii(73) = 57 '9 DIK_NUMPAD9 = 73
DItoAscii(74) = 45 '- DIK_SUBTRACT = 74
DItoAscii(75) = 52 '4 DIK_NUMPAD4 = 75
DItoAscii(76) = 53 '5 DIK_NUMPAD5 = 76
DItoAscii(77) = 54 '6 DIK_NUMPAD6 = 77
DItoAscii(78) = 43 '+ DIK_ADD = 78
DItoAscii(79) = 49 '1 DIK_NUMPAD1 = 79
DItoAscii(80) = 50 '2 DIK_NUMPAD2 = 80
DItoAscii(81) = 51 '3 DIK_NUMPAD3 = 81
DItoAscii(82) = 48 '0 DIK_NUMPAD0 = 82
DItoAscii(83) = 46 '. DIK_DECIMAL = 83
DItoAscii(84) = 0 'F11 DIK_F11 = 87 'Define ones I'm not sure about or will not use as 0 (null)
DItoAscii(85) = 0 'F12 DIK_F12 = 88
DItoAscii(86) = 13 'Enter DIK_NUMPADENTER = 156
DItoAscii(87) = 0 'Ctrl DIK_RCONTROL = 157
DItoAscii(88) = 47 '/ DIK_DIVIDE = 181
DItoAscii(89) = 0 'Alt DIK_RALT = 184 'Define ones I'm not sure about or will not use as 0 (null)
DItoAscii(90) = 0 'Home DIK_HOME = 199
DItoAscii(91) = 0 'Up DIK_UP = 200
DItoAscii(92) = 0 'Page Up DIK_PAGEUP = 201
DItoAscii(93) = 0 'Left DIK_LEFT = 203
DItoAscii(94) = 0 'Right DIK_RIGHT = 205
DItoAscii(95) = 0 'End DIK_END = 207
DItoAscii(96) = 0 'Down DIK_DOWN = 208
DItoAscii(97) = 0 'Page Down DIK_PAGEDOWN = 209
DItoAscii(98) = 0 'Insert DIK_Insert = 210
DItoAscii(99) = 0 'Delete DIK_Delete = 211

'Define ones I'm not sure about or will not use as 0 (null)
'Define all the rest as 0 (null).
For X = 100 To UBound(DItoAscii)
DItoAscii(X) = 0
Next
End Function


原帖地址:

http://www.xtremevbtalk.com/archive/index.php/t-94359.html

评论: 0 | 引用: 0 | 查看次数: 917