Sign in to follow this  
EasyGino

DirectInput Multi-Key

Recommended Posts

When I've used DirectX keyboard stuff, I've tied two event handlers to the keyboard - one for keys being pressed, another for keys being released. Let's say you have an (x,y) coordinate for something. I'd have two extra variables - dx and dy, which are added to the x and y once a "game loop". When I trap a key pressed down, I then check the key- if it's left, dx=-1, if it's right, dx=1, id it's up, dy=-1 and if it's down dy=1.
In the key release event, I'll check which key again - if it's left or right, dx=0 and if it's up or down dy=0. This is the easiest way, but doesn't check for press-hold-up-then-tap-and-release-down-whilst-still-holding-up type situations (you'd expect the object to keep moving up, it'd actually just stop). I don't know if DX has this built-in, but you could always create a 256-long array of booleans and store whether a key is pressed or not into that, then check those as you run your game loop.

Share this post


Link to post
Share on other sites
A word of caution on keyboard input: If you're having trouble getting your keyboard to register multiple keypresses simultaneously, it may be a hardware issue with your keyboard. Various keyboards have difficulties with certain keypress combinations. For example, my keyboard cannot handle the LEFT-ARROW and UP-ARROW at the same time as the spacebar.

You should always allow your users to re-define your game's keyboard mapping, to ensure that strange harware issues such as this won't prevent them from playing the game!


Ryan

Share this post


Link to post
Share on other sites
Hehe, I'm glad you didn't have to pull your hair out over that "bug" :)

There are certain key combinations that seem to be ideal for games. I've never seen a keyboard where the CTRL, ALT or SHIFT keys conflicted with any of the arrow keys, making these ideal for "weapons" keys. Using those keys as the default setup for your game will likely result in fewer frustrated users!


Ryan

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this