Sign in to follow this  
synth_cat

keyboard doesn't detect SPACE and LEFT at same time

Recommended Posts

synth_cat    306
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
Mastaba    761
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
Sneftel    1788
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
Evil Steve    2017
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
    synth_cat    306
    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
    Krohm    5030
    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
    Evil Steve    2017
    Quote:
    Original post by synth_cat
    Thanks, Krohm!

    By the way, do VK codes range from 0 to 255 in the same way DIK codes do?
    I'd guess they do, looking at the defines in winuser.h (Highest is 0xfe). They're also defined as double-digit hex numbers, which implies they're probably just BYTE values. But as far as I'm aware, it's not guaranteed.

    Share this post


    Link to post
    Share on other sites
    synth_cat    306
    Quote:

    I'd guess they do, looking at the defines in winuser.h (Highest is 0xfe). They're also defined as double-digit hex numbers, which implies they're probably just BYTE values. But as far as I'm aware, it's not guaranteed.


    That's one of the reasons I'm wary of doing this; the VK codes seem to change randomly from machine to machine. At any rate, they aren't as "definite" as the DIK codes. At least that's the impression I get. . .

    Share this post


    Link to post
    Share on other sites
    Mastaba    761
    The VK codes do not vary from machine to machine. It is just that some keyboards may have some keys that other keyboards don't have, and those VK codes are still just as constant.

    Share this post


    Link to post
    Share on other sites
    Trillian    410
    Quote:
    Original post by Evil Steve
    The above points also go for using DirectInput for mouse input too.


    Could you explain how it is possible, using the WinAPI, to detect physical mouse moves, and not cursor moves (like if you're at the edge of the screen and you move, the cursor won't move but you still get to know that the physical mouse has moved)?

    Share this post


    Link to post
    Share on other sites
    Evil Steve    2017
    Quote:
    Original post by Trillian
    Quote:
    Original post by Evil Steve
    The above points also go for using DirectInput for mouse input too.


    Could you explain how it is possible, using the WinAPI, to detect physical mouse moves, and not cursor moves (like if you're at the edge of the screen and you move, the cursor won't move but you still get to know that the physical mouse has moved)?


    See Taking Advantage of High-Definition Mouse Movement in the DirectX SDK. Basically, you use WM_INPUT for raw input.

    Share this post


    Link to post
    Share on other sites
    synth_cat    306
    Back to my original question: will switching to Windows messages for KB input fix the problem where two keys cannot be pressed at the same time on certain systems?

    Share this post


    Link to post
    Share on other sites
    owl    376
    how is it possible that after 20 years of PC gaming, keyboards still show this stupid problem?

    Share this post


    Link to post
    Share on other sites
    jollyjeffers    1570
    Quote:
    Original post by synth_cat
    Back to my original question: will switching to Windows messages for KB input fix the problem where two keys cannot be pressed at the same time on certain systems?
    Not necessarily. As the thread Dave Hunt linked to explains (via further links) it's an electrical issue. It's not software.

    Keyboards were designed for typing 'proper' words and sentences; I don't really believe it, but ISTR being told the QWERTY layout was originally to slow people down [lol]. Using ASDW/arrow keys for gaming isn't really what keyboards were designed for.

    Quote:
    how is it possible that after 20 years of PC gaming, keyboards still show this stupid problem?
    I've got a feeling the interface mechanism is also part of the problem. That is, the PS/2 signalling standard can't express it any better than the (broken) hardware can... But I'm not 100% sure of that [smile]

    hth
    Jack

    Share this post


    Link to post
    Share on other sites
    owl    376
    Quote:
    Original post by jollyjeffers

    Quote:
    how is it possible that after 20 years of PC gaming, keyboards still show this stupid problem?
    I've got a feeling the interface mechanism is also part of the problem. That is, the PS/2 signalling standard can't express it any better than the (broken) hardware can... But I'm not 100% sure of that [smile]


    Do you know if USB keyboard behave like this also? That would be just great.

    Share this post


    Link to post
    Share on other sites
    iMalc    2466
    Quote:
    Original post by Evil Steve
    Personally, I just have an array of 256 entries, and update them according to WM_KEYDOWN and WM_KEYUP messages.
    Wow amazing, that is exactly what I do for my software 3D engine!
    I catch WM_SYSKEYDOWN and WM_SYSKEYUP too though, and have an efficient and versatile binding mechanism allowing the user to bind operations to individual shift keys for example.
    And I thought I was just weird. (I can see that being quoted back to me in a moment)

    Anyway, as stated, this is probably a hardware, not software, issue.

    Share this post


    Link to post
    Share on other sites
    jollyjeffers    1570
    Quote:
    Original post by owl
    Do you know if USB keyboard behave like this also? That would be just great.
    I have to be honest and say no: I don't know [headshake]

    Purely from experimentation (I occasionally use USB keyboards) the same thing happens, so wherever the source it doesn't seem to go away...

    hth
    Jack

    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