Jump to content
  • Advertisement
Sign in to follow this  
synth_cat

keyboard doesn't detect SPACE and LEFT at same time

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

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!

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

    Share this post


    Link to post
    Share on other sites
    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.)

    Share this post


    Link to post
    Share on other sites
    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.

    Share this post


    Link to post
    Share on other sites
    Sign in to follow this  

    • 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!