Jump to content

  • Log In with Google      Sign In   
  • Create Account

Direct Input DIK_* defines are in incorrect order for keyboard


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Kest   Members   -  Reputation: 547

Like
0Likes
Like

Posted 18 February 2012 - 08:10 AM

Hey guys. Haven't posted on here for a while. Looks like things have changed since I last did.

Anyway, I'm testing my game engine on a laptop, which I know has less keys than a standard keyboard, but what I didn't know is that the scan codes are in a different order for some reason. From what I read in the directX manual, DIK_* defines are supposed to line up with the dwOfs member of the DIDEVICEOBJECTDATA structure. However, on this laptop, the [ key is at offset=145, while the ] key is offset=26. IE, the DIK_LBRACKET define DOES NOT corrispond with the [ key. In fact, many of the non-ascii type keys, like brackets and symbols, do not match up with the direct input DIK_* defines. Further, when I attempted to use the "code to ascii" conversion system posted here (at http://www.gamedev.net/page/resources/_/technical/directx-and-xna/converting-scan-codes-to-ascii-r842 ), it outputs the wrong keys for these brackets.

My question is this: Is this likely..
1) Typical behavior?
2) Some type of glitch in hardware or software within the computer? IE, badly ordered keyboard scan codes.
3) A mistake in my code somewhere.

Here are the scan codes I printed out from my game's log:
Key 0 / tszName= Esc / Offset = 1
Key 1 / tszName= 1 / Offset = 2
Key 2 / tszName= 2 / Offset = 3
Key 3 / tszName= 3 / Offset = 4
Key 4 / tszName= 4 / Offset = 5
Key 5 / tszName= 5 / Offset = 6
Key 6 / tszName= 6 / Offset = 7
Key 7 / tszName= 7 / Offset = 8
Key 8 / tszName= 8 / Offset = 9
Key 9 / tszName= 9 / Offset = 10
Key 10 / tszName= 0 / Offset = 11
Key 11 / tszName= - / Offset = 12
Key 12 / tszName= Backspace / Offset = 14
Key 13 / tszName= Tab / Offset = 15
Key 14 / tszName= Q / Offset = 16
Key 15 / tszName= W / Offset = 17
Key 16 / tszName= E / Offset = 18
Key 17 / tszName= R / Offset = 19
Key 18 / tszName= T / Offset = 20
Key 19 / tszName= Y / Offset = 21
Key 20 / tszName= U / Offset = 22
Key 21 / tszName= I / Offset = 23
Key 22 / tszName= O / Offset = 24
Key 23 / tszName= P / Offset = 25
Key 24 / tszName= ] / Offset = 26
Key 25 / tszName= \ / Offset = 27
Key 26 / tszName= Enter / Offset = 28
Key 27 / tszName= Ctrl / Offset = 29
Key 28 / tszName= A / Offset = 30
Key 29 / tszName= S / Offset = 31
Key 30 / tszName= D / Offset = 32
Key 31 / tszName= F / Offset = 33
Key 32 / tszName= G / Offset = 34
Key 33 / tszName= H / Offset = 35
Key 34 / tszName= J / Offset = 36
Key 35 / tszName= K / Offset = 37
Key 36 / tszName= L / Offset = 38
Key 37 / tszName= ; / Offset = 39
Key 38 / tszName= Shift / Offset = 42
Key 39 / tszName= \ / Offset = 43
Key 40 / tszName= Z / Offset = 44
Key 41 / tszName= X / Offset = 45
Key 42 / tszName= C / Offset = 46
Key 43 / tszName= V / Offset = 47
Key 44 / tszName= B / Offset = 48
Key 45 / tszName= N / Offset = 49
Key 46 / tszName= M / Offset = 50
Key 47 / tszName= , / Offset = 51
Key 48 / tszName= . / Offset = 52
Key 49 / tszName= / / Offset = 53
Key 50 / tszName= Right Shift / Offset = 54
Key 51 / tszName= * / Offset = 55
Key 52 / tszName= Alt / Offset = 56
Key 53 / tszName= Space / Offset = 57
Key 54 / tszName= Caps Lock / Offset = 58
Key 55 / tszName= F1 / Offset = 59
Key 56 / tszName= F2 / Offset = 60
Key 57 / tszName= F3 / Offset = 61
Key 58 / tszName= F4 / Offset = 62
Key 59 / tszName= F5 / Offset = 63
Key 60 / tszName= F6 / Offset = 64
Key 61 / tszName= F7 / Offset = 65
Key 62 / tszName= F8 / Offset = 66
Key 63 / tszName= F9 / Offset = 67
Key 64 / tszName= F10 / Offset = 68
Key 65 / tszName= Num Lock / Offset = 69
Key 66 / tszName= Scroll Lock / Offset = 70
Key 67 / tszName= Num 7 / Offset = 71
Key 68 / tszName= Num 8 / Offset = 72
Key 69 / tszName= Num 9 / Offset = 73
Key 70 / tszName= - / Offset = 74
Key 71 / tszName= Num 4 / Offset = 75
Key 72 / tszName= Num 5 / Offset = 76
Key 73 / tszName= Num 6 / Offset = 77
Key 74 / tszName= + / Offset = 78
Key 75 / tszName= Num 1 / Offset = 79
Key 76 / tszName= Num 2 / Offset = 80
Key 77 / tszName= Num 3 / Offset = 81
Key 78 / tszName= Num 0 / Offset = 82
Key 79 / tszName= Num Del / Offset = 83
Key 80 / tszName= F11 / Offset = 87
Key 81 / tszName= F12 / Offset = 88
Key 82 / tszName= Kana / Offset = 112
Key 83 / tszName= Convert / Offset = 121
Key 84 / tszName= No Convert / Offset = 123
Key 85 / tszName= F14 / Offset = 125
Key 86 / tszName= = / Offset = 144
Key 87 / tszName= [ / Offset = 145
Key 88 / tszName= ' / Offset = 146
Key 89 / tszName= ` / Offset = 148
Key 90 / tszName= Num Enter / Offset = 156
Key 91 / tszName= Right Ctrl / Offset = 157
Key 92 / tszName= Num / / Offset = 181
Key 93 / tszName= Prnt Scrn / Offset = 183
Key 94 / tszName= Right Alt / Offset = 184
Key 95 / tszName= Pause / Offset = 197
Key 96 / tszName= Home / Offset = 199
Key 97 / tszName= Up / Offset = 200
Key 98 / tszName= Page Up / Offset = 201
Key 99 / tszName= Left / Offset = 203
Key 100 / tszName= Right / Offset = 205
Key 101 / tszName= End / Offset = 207
Key 102 / tszName= Down / Offset = 208
Key 103 / tszName= Page Down / Offset = 209
Key 104 / tszName= Insert / Offset = 210
Key 105 / tszName= Delete / Offset = 211
Key 106 / tszName= Left Windows / Offset = 219
Key 107 / tszName= Right Windows / Offset = 220
Key 108 / tszName= Application / Offset = 221

Thank you for any help.

Sponsor:

#2 Kest   Members   -  Reputation: 547

Like
0Likes
Like

Posted 18 February 2012 - 12:43 PM

Well, I searched and found a keyboard testing program which reports which scan codes a keyboard uses for each key, and it seems that the keyboard is working fine. Within the program, the ] key reports scan code 27, which is after [, and all other keys seem correct. So it appears that I am some-how getting the wrong dwOfs value in my enumerating callback function. I check the value ASAP within the actual enumeration function, and it is wrong from the get-go.

Any ideas on how I can even begin trying to fix this? Anyone have their own direct input program laying around that shows the scan code for keys being pressed? That way, I could determine if my code is causing this somewhere,or if my keyboard just doesn't play nice with DirectInput. Unfortunately, the direct input samples do not include such a program.

#3 Evil Steve   Members   -  Reputation: 1982

Like
0Likes
Like

Posted 19 February 2012 - 04:51 PM

This doesn't answer your question, but you really shouldn't use DirectInput for keyboard input, it has no advantages over standard window messages, and several disadvantages:
1. It's nontrivial to work with, as you're discovering.
2. It's slower (It spawns a seperate thread to capture raw input)
3. You can't use it for keyboard input without having to code support for key repeat, different keyboard layouts and IMEs, caps lock, shift, and all the other things you take for granted with window messages.

Steve Macpherson
Systems Programmer

Rockstar North





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS