Jump to content
Site Stability Read more... ×
  • Advertisement
Sign in to follow this  
LPVOID_CH

DirectInput and ASCII Codes

This topic is 5166 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

hi all. how can you get ASCII codes from the keyboard with direct input? i'm writing a console for my game and i dont want to test all keys with DIK_A, DIK_B, ... thx

Share this post


Link to post
Share on other sites
Advertisement
You might be better off collecting WM_CHAR messages in your Windows message loop for text input. It gives you support for international characters, as well as things like autorepeat.

Share this post


Link to post
Share on other sites
I'm fighting with the same problem (though not using DInput). I was thinking about using a similar function to the one given in that article:

static int scan2ascii(DWORD scancode, ushort* result)
{
static HKL layout=GetKeyboardLayout(0);
static uchar State[256];

if (GetKeyboardState(State)==FALSE)
return 0;
UINT vk=MapVirtualKeyEx(scancode,1,layout);
return ToAsciiEx(vk,scancode,State,result,0,layout);
}



But I'm concerned of the performance issues. What if you call this function numerous times in one frame? Wouldn't GetKeyboardLayout and GetKeyboardState be doing redundant work?


At any rate, if you have a key input manager already taking the keyboard state each frame, I would imagine that just calling ToAscii would be enough. That, I suspect, is what I will be doing.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!