keyboard doesn't detect SPACE and LEFT at same time

Started by
20 comments, last by jollyjeffers 16 years, 9 months ago
On a certain computer running Vista, my game doesn't pick up the the LEFT key when SPACE is already being pressed. Is this because I'm using DirectInput for KB, or is there something else I need to fix? Thanks!
Greg Philbrick, Game Developercoming soon . . . Overhauled CellZenith
Advertisement
My Vista based computer has no problem detecting both space and left simultaneously, in your game. There is probably little you can do other than make the game controls user configurable and have the user setup the controls to something that works better.

[Edited by - Mastaba on July 9, 2007 4:42:16 PM]
.
Have a look at this topic and the several links provided therein.

[Edited by - Dave Hunt on July 9, 2007 2:22:43 PM]
If you're seeing this issue with only two keys, then you either have the cheapest and worst-engineered keyboard known to man, or your problem is not electrical.

For keyboard input, there are few reasons to use DInput, and many reasons not to. If I were you, I'd switch to window messages.
What are the reasons? Is it still possible that this problem is because of using DInput?
Greg Philbrick, Game Developercoming soon . . . Overhauled CellZenith
Quote:Original post by synth_cat
What are the reasons? Is it still possible that this problem is because of using DInput?
Only if it's due to your code (Which is doubtful if it only occurs with these two keys).

Are other games able to detect Left and Space at the same time? If not, it may well be electrical.

Reasons against using DirectInput for keyboard input:
  • It creates a seperate thread to just read data from the keyboard using raw input (Which you can do yourself with Win32), meaning there's more overhead than just doing it yourself.
  • No support for keyboard repeat at the rate the user has set in the control pannel - you have to re-invent this yourself. Not too bad for game input, but a pain for GUI-style text input.
  • No support for capital letters and shifted characters - you have to detect caps lock / shift being held as well as your normal character.
  • No support for caps lock on/off; it's handled by a higher layer than DirectInput, so if someone starts your game with caps lock on, it gets confused.
  • More code to get the same effect as Window Messages.

    Overall, there's no real reason to use DirectInput for keyboard input over GetAsyncKeyState() or window messages (Because you're pumping all your window messages each frame anyway, right?). Personally, I just have an array of 256 entries, and update them according to WM_KEYDOWN and WM_KEYUP messages. For GUI-style text, I use the WM_CHAR message.

    The above points also go for using DirectInput for mouse input too. DirectInput is only really suited for joystick input (And XInput for the Xbox 360 controller).
  • Thanks for clearing that up!
    Greg Philbrick, Game Developercoming soon . . . Overhauled CellZenith
    I remember that GetAsyncKeyState was kind of unresponsive and slow. Does using WM_KEYDOWN and WM_KEYUP have the same problem?

    Also, I have to ask: Should I really go to all the trouble of tearing out the DirectInput architecture I already have when my game seems to be working completely fine with Dinput for keyboard already?

    (If I were to switch to VK codes, I would have to go write a new huge switch statement for code-to-string conversion, which would be unpleasant.)
    Greg Philbrick, Game Developercoming soon . . . Overhauled CellZenith
    Quote:Original post by synth_cat
    I remember that GetAsyncKeyState was kind of unresponsive and slow. Does using WM_KEYDOWN and WM_KEYUP have the same problem?
    I have never experienced issues with DI but when I switched to WM, I observed no real difference. At very low FPS the WM approach seemed more robust nut there's little I care for at 10fps.
    Quote:Original post by synth_cat
    Also, I have to ask: Should I really go to all the trouble of tearing out the DirectInput architecture I already have when my game seems to be working completely fine with Dinput for keyboard already?
    Yes, absolutely! I did this, as many others and the benefit from having an unified system gave me a real benefit in the form of less code to manage and simplier code!
    Quote:Original post by synth_cat
    (If I were to switch to VK codes, I would have to go write a new huge switch statement for code-to-string conversion, which would be unpleasant.)
    Not necessarily! There's a Win32 function which does this in a language-dependant way so it gets automatically localized!
    If memory serves it's called GetKeyName.

    Previously "Krohm"

    Thanks, Krohm!

    By the way, do VK codes range from 0 to 255 in the same way DIK codes do?
    Greg Philbrick, Game Developercoming soon . . . Overhauled CellZenith

    This topic is closed to new replies.

    Advertisement