• Advertisement
Sign in to follow this  

DirectInput Buffered Keyboard

This topic is 4803 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement