views:

30

answers:

1

Hello. I have just tested my DirectX game on a Windows 2000 SP4 system but it won't receive any mouse clicks!

This is how I check for mouse clicks :

    unsigned int mButtons = 0;
    if (GetKeyState(VK_LBUTTON) < 0) mButtons |= HIDBoss::MOUSE_LEFT;
    if (GetKeyState(VK_RBUTTON) < 0) mButtons |= HIDBoss::MOUSE_RIGHT;
    if (GetKeyState(VK_MBUTTON) < 0) mButtons |= HIDBoss::MOUSE_MIDDLE;
    if (GetKeyState(VK_XBUTTON1) < 0) mButtons |= HIDBoss::MOUSE_4;
    if (GetKeyState(VK_XBUTTON2) < 0) mButtons |= HIDBoss::MOUSE_5;

etc...

This code works perfectly on Windows 7 and XP 32/64bit.

The problem is fixed if I use the OIS library instead - which uses DirectX input - but it contains a few bugs so I would rather avoid it.

Can anyone suggest why GetKeyState won't work on W2K? Could it be because the system hasn't been updated - through Windows Update - for the last couple of years..?

Thank you for your time,

Bill

+1  A: 

I'm not sure why it doesn't work but I'd recommend using GetAsyncKeyState instead.

Edit: In answer to your comment. It is merely a suggestion but its, equally, pretty easy to find out if the buttons are swapped by calling:

GetSystemMetrics(SM_SWAPBUTTON)

Your big problem arises from the fact that GetKeyState is not supposed to return a value for mouse buttons only keyboard buttons. the fact it DOES work in some OSs is not something you are supposed to be able to rely on across all OSs.

An application calls GetKeyState in response to a keyboard-input message. This function retrieves the state of the key when the input message was generated.

Its worth noting that it makes specific mention of calling it in response to a keyboard-input message (ie WM_KEY[UP/DOWN]). Equally there is no mention that this should work for mice. As such you really are better off just using GetAsyncKeyState...

Goz
Could you please elaborate a bit more on this? The docs say that it returns the physical button events rather than the logical "mapped" ones. Is there a good reason why I should "confuse" those users who are used to clicking the other way round? Of course I will try it and if it does work, then that's a good enough reason! But is there something else I should be aware of? Thanks!
Bill Kotsias
@Bill: Updated.
Goz