From: Ryan Norton Date: Sat, 6 Nov 2004 06:41:05 +0000 (+0000) Subject: rewrite wxGetKeyState a bit, spun from [ 1058347 ] Fixes wxGetKeyState X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/84c51ddf7771e9841645a52c899393215a8a6464 rewrite wxGetKeyState a bit, spun from [ 1058347 ] Fixes wxGetKeyState git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30316 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/msw/window.cpp b/src/msw/window.cpp index de07d46ad1..bcba0c04c8 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -5133,25 +5133,32 @@ WXWORD wxCharCodeWXToMSW(int id, bool *isVirtual) bool wxGetKeyState(wxKeyCode key) { bool bVirtual; - WORD vkey = wxCharCodeWXToMSW(key, &bVirtual); - SHORT state; - switch (key) +//High order with GetAsyncKeyState only available on WIN32 +#ifdef __WIN32__ + //If the requested key is a LED key, return + //true if the led is pressed + if (key == WXK_NUMLOCK || + key == WXK_CAPITAL || + key == WXK_SCROLL) { - case WXK_NUMLOCK: - case WXK_CAPITAL: - case WXK_SCROLL: - // get the toggle state of the special key - state = GetKeyState(vkey); - break; +#endif + //low order bit means LED is highlighted, + //high order means key is down + //Here, for compat with other ports we want both + return GetKeyState( wxCharCodeWXToMSW(key, &bVirtual) ) != 0; - default: - // Get the current state of the physical key - state = GetAsyncKeyState(vkey); - break; +#ifdef __WIN32__ } - // if the most significant bit is set then the key is down - return ( state & 0x0001 ) != 0; + else + { + //normal key + //low order bit means key pressed since last call + //high order means key is down + //We want only the high order bit - the key may not be down if only low order + return ( GetAsyncKeyState( wxCharCodeWXToMSW(key, &bVirtual) ) & (1<<15) ) != 0; + } +#endif } wxWindow *wxGetActiveWindow()