Direct Input

Started by
5 comments, last by amoeba 22 years, 11 months ago
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.
Advertisement
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?
EG...
#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~
No thats not what I am on about.

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

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......?
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...

Ian Halliday yoPWEENED
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

Ian Halliday yoPWEENED
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.


Seeya
Krippy
Thanks - that was EXACTLY what I was after :-)

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

Amoeba.

This topic is closed to new replies.

Advertisement