Archived

This topic is now archived and is closed to further replies.

Zoomby

DirectInput - ScanCode to Ascii

Recommended Posts

hi! I found a function which converts DirectInput scancode to ascii code. Now, when I want to make a input field in my game, how do I get the scancode of the key which was pressed? Do I have to iterate throw the inputbuffer array to find which key is currently pressed, or is there a more elegant way? bye chris

Share this post


Link to post
Share on other sites
hi,

@ Pipo:
This way is NOT more elegant, I think. You really would write a giant switch statement for nearly every key on the keyboard?

@ cannelbrae:
thanks, I totally forgot that. :-). I believed there would be an easy DirectInput solution.

bye
chris

[edited by - Zoomby on May 3, 2003 12:57:25 PM]

Share this post


Link to post
Share on other sites
Since the DIK_x values are actually indexes into a 256 character array, you could create a static array that holds all those upper, lower and system character codes and just index it by the DIK_x code you get. No if-elses, for loops needed.

As far as DInput only being used for button presses, that may be the case but it is NOT very difficult to write routines to do it for you. That way you don''t have to worry about routing WM_xxx messages and DInput messages.

Share this post


Link to post
Share on other sites
It may work for YOUR keyboard, but that doesn''t mean it will work elsewhere. DI doesn''t take locale into account. For instance, if I remember correctly... in German Z and Y are swapped. In France, A and W (or was it Q?) are swapped. What about accented characters? etc.

Windows messages take care of all of this for you. Why ignore it?

Share this post


Link to post
Share on other sites
hi, thank for all the replies.

I think I''ll use windows WM_CHAR messages. That''s in fact very easy. The only problem is, that you have to mix two different techniques (DirectInput keyboard handling and windows message keyboard handling). In my case the class which needs the text input will be a singleton, so accessing it even from WinProc wouldn''t be hard, I think.

bye
chris

Share this post


Link to post
Share on other sites