C++ Key Press?

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
Sk8er

C++ Key Press?

Post by Sk8er »

I am very confused on this. Been doing searches on google all morning. Anyone got a decent explanation of how to? I would like WASD and The arrow keys to move a sprite. (Currently in my game its completely random on how the character moves.)


EDIT:: NVM, i got the arrows.
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: C++ Key Press?

Post by XianForce »

Sk8er wrote:I am very confused on this. Been doing searches on google all morning. Anyone got a decent explanation of how to? I would like WASD and The arrow keys to move a sprite. (Currently in my game its completely random on how the character moves.)


EDIT:: NVM, i got the arrows.
Just for future reference, it's usually helpful to list the API/Library you are using.
DaveB
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 24
Joined: Sat Nov 21, 2009 1:57 pm

Re: C++ Key Press?

Post by DaveB »

you can use a combination of _kbhit() (to check if a key was hit) and _getch() (to get the value of the key that was hit).
if you are using an API such as SDL, there is an event called SDL_KEYDOWN you can check when polling for events
Post Reply