Jump to content
  • Advertisement


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


Direct Input

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

I am using the NeHe DirectInput tutorial, and I want to be able to print out what character the user has pressed, ie if keystate[101] is pressed what character does this correspond too? Anyone know if there is an easy way to do this (i.e. some direct input proc) or do I have to work it all out myself and have a HUGE if statement?? Cheers, Alex. P.S. the reason I need this is because I am developing a Quake-Style console.

Share this post

Link to post
Share on other sites
there are macros in the DX eaders that have the scan codes for all the keys on the KB if thats what ure asking about?
#define DIK_ESCAPE 0x01
#define DIK_1 0x02
#define DIK_2 0x03
#define DIK_3 0x04
#define DIK_4 0x05
#define DIK_5 0x06
#define DIK_6 0x07
#define DIK_7 0x08
#define DIK_8 0x09
#define DIK_9 0x0A
#define DIK_0 0x0B
#define DIK_MINUS 0x0C /* - on main keyboard */
#define DIK_EQUALS 0x0D
#define DIK_BACK 0x0E /* backspace */
#define DIK_TAB 0x0F

if u want to just print the charecter to the screen like when ure typing in a word processor, it depends on what u are using to display text.

~prevail by daring to fail~

Share this post

Link to post
Share on other sites
No thats not what I am on about.

I want to be able to say
keystate[x] = ''y''
keystate[n] = ''b''
keystate = ''2''

So that when a user presses a key (and sets keystate[x] to 1/true), I can PRINT out that character in my console.

There must be an easier way than having a massive if/case statement......?

Share this post

Link to post
Share on other sites
Using keystates for a console or any kind of string input is a bad idea. It seems great at first, and you think to yourself that there is no way you''re going to touch buffered input cause you want to do it all yourself (well, that was how i was). But man, holy cow its not worth the trouble. Buffered input is a lot easier to use once you get it working. You can always switch between buffered and immediate input so you can still use keystates for your game.

Put in somekind of input subsystem into your game/program and when the console is opened, switched to the buffered mode of your input subsystem...

uh, other stuff. I dunno, i''m probably missing something but my eye feels puffy even though it isn''t and i''m tired and stuff and ya know, and and and.

er, yeah. i''m not drunk...

Share this post

Link to post
Share on other sites
i just realized that buffered input might not solve your problem. I haven''t used directinput for a while. I don''t remember if buffered input still returns scancodes for the key presses...

um, i also just looked at some old code a wrote and noticed that to the problem you''re having (that i also had) i just wrote a function that takes the scancode, checks if shift is down and does a big if else if block... theres got to be a better way

i dunno. sorry, i''m not much help am i

Share this post

Link to post
Share on other sites
Actually I think for a console you might want to think about using Windows keyboard messages instead. With the standard Windows input you can easily get the key that was pressed with capitalization, etc.

case WM_CHAR:
unsigned char charcode = (unsigned char)wParam;

Put that in your message loop and when a key that corresponds to a screen character is pressed you will receive the correct character code in charcode
This will also handle auto-repeating and click-delays so you won''t have to worry about implementing them yourself

Then use DI when the action is happening for fast responsiveness.


Share this post

Link to post
Share on other sites
Thanks - that was EXACTLY what I was after :-)

I still think there MUST be some kind of DirectInput function to do it though :-P


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!