Skip to main content
gamedev.net
🔒 Locked

DirectInput Buffered Keyboard

Started by FenixRoA 6 replies 950+ views
Original Post
FenixRoA
FenixRoA
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)?
FenixRoA
FenixRoA
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...
FenixRoA
FenixRoA
a simple yes or no answer would b fine at this point
ph33r
ph33r
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
dweeb
dweeb
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.

______ohh well what the heck lets try it?
FenixRoA
FenixRoA
Which events do I have to hook into and what namespace are they in?
ph33r
ph33r
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.