DirectInput Buffered Keyboard

Recommended Posts

FenixRoA    142
OK, so I switched to a buffered keyboard. The codes that come in however are almost nonsensical garbage. The keys do not match up to any ASCII or Unicode chart but rather to whatever the hardware sends. So I have been mapping each letter, number, and control key (shift, enter, insert, etc.) into an array, and now I have a massive class that handles all things keyboard related. The struct for each key is as follows:
[source language = "c#"]
public struct OneKey
{

public enum State
{
Norm = 0,
Shift= 1
}

public bool hasChar;
public byte KeyCode;
public char [] KeyChar;

public OneKey(byte kCode,char kChar, char ShiftChar)
{
hasChar = true;
KeyCode = kCode;
KeyChar = new Char [2];
KeyChar[State.Norm] = kChar;
KeyChar[State.Shift] = ShiftChar;
}

public OneKey(byte kCode, char kChar)
{
hasChar = true;
KeyCode = kCode;
KeyChar = new Char[1];
KeyChar[State.Norm] = kChar;
}
public OneKey(byte kCode)
{
hasChar = false;
KeyCode = kCode;
}
}


Is this the best way to go about this? is there no function that will do this for me (give me the character (or string) represented by the key pressed or the keycode (as I require) that is affected by caps lock and shift as necessary)?

Share on other sites
FenixRoA    142
Please guys... All I want to know if there is any function or method that can convert each keycode to its appropriate letter/ASCII/Unicode form...

Share on other sites
FenixRoA    142
a simple yes or no answer would b fine at this point

Share on other sites
ph33r    380
To my knowledge there is no such dinput function or macro to handle this. You'll have to roll your own switch statement ala

DWORD keyPressed;
switch( keyPressed )
{
case DIK_A:
case DIK_B:
.
.
.
case DIK_Z:
};

I just double checked the dinput documentation and I didn't find any, regardless it shouldn't take you longer then 10 mins to write a function to do the conversion for you.

- Dave Neubelt

Share on other sites
dweeb    128
DirectInput is not really designed to work with text input.

I suggest that you use the normal windows events for regular textinputs and directX for controlling the character.

Share on other sites
FenixRoA    142
Which events do I have to hook into and what namespace are they in?

Share on other sites
ph33r    380
If you're going to go the winproc route of using text-input you will want to catch the WM_CHAR message. Remeber in your message loop, you need to call TranslateMessage to turn those WM_KEYDOWN message's into WM_CHAR's. I believe the wParam of WM_CHAR tell's you if shift is being held or capslock is on, but it could be the lword, you'll have to double check the docs.

But going against the previous posters advice I'd write a function that takes a direct input DWORD and converts it to a char, it's a quick copy paste job.

- Dave Neubelt

Share on other sites
turnpast    1011
take a look at
http://www.gamedev.net/reference/programming/features/scan2asc/
.
Yuck.
To do this in Managed land you need to pinvoke User32.dll. If you are interested in following this path browse through the Common directory of of the Managed samples in the oct 2004 update, they do a bunch of similar garbage.