wxGetKeyState as per feature request :).

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24854 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Ryan Norton
2003-12-14 23:35:21 +00:00
parent c10eeb63ba
commit 6ed892f3f2
5 changed files with 112 additions and 0 deletions

View File

@@ -80,6 +80,11 @@ WXDLLIMPEXP_BASE wxChar* copystring(const wxChar *s);
// Sound the bell // Sound the bell
WXDLLIMPEXP_BASE void wxBell(); WXDLLIMPEXP_BASE void wxBell();
#if defined(__WXGTK__) || defined(__WXMSW__) || defined(__WXMAC__) || defined(__X__)
// Get the state of a key (true if pressed, false if not)
WXDLLIMPEXP_BASE bool wxGetKeyState(wxKeyCode key);
#endif
// Get OS description as a user-readable string // Get OS description as a user-readable string
WXDLLIMPEXP_BASE wxString wxGetOsDescription(); WXDLLIMPEXP_BASE wxString wxGetOsDescription();

View File

@@ -1757,6 +1757,42 @@ long wxMacTranslateKey(unsigned char key, unsigned char code)
return retval; return retval;
} }
int wxKeyCodeToMacModifier(wxKeyCode key)
{
switch (key)
{
case WXK_START:
return cmdKey;
case WXK_SHIFT:
return shiftKey;
case WXK_CAPITAL:
return alphaLock;
case WXK_OPTION:
return optionKey;
case WXK_CONTROL:
return controlKey;
default:
return 0;
}
}
bool wxGetKeyState(wxKeyCode key) //virtual key code if < 10.2.x, else see below
{
//if OS X > 10.2 (i.e. 10.2.x)
//a known apple bug prevents the system from determining led
//states with GetKeys... can only determine caps lock led
return !!(GetCurrentKeyModifiers() & wxKeyCodeToMacModifier(key));
//else
// KeyMapByteArray keymap;
// GetKeys((BigEndianLong*)keymap);
// return !!(BitTst(keymap, (sizeof(KeyMapByteArray)*8) - iKey));
}
#if !TARGET_CARBON #if !TARGET_CARBON
void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr ) void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
{ {

View File

@@ -1757,6 +1757,42 @@ long wxMacTranslateKey(unsigned char key, unsigned char code)
return retval; return retval;
} }
int wxKeyCodeToMacModifier(wxKeyCode key)
{
switch (key)
{
case WXK_START:
return cmdKey;
case WXK_SHIFT:
return shiftKey;
case WXK_CAPITAL:
return alphaLock;
case WXK_OPTION:
return optionKey;
case WXK_CONTROL:
return controlKey;
default:
return 0;
}
}
bool wxGetKeyState(wxKeyCode key) //virtual key code if < 10.2.x, else see below
{
//if OS X > 10.2 (i.e. 10.2.x)
//a known apple bug prevents the system from determining led
//states with GetKeys... can only determine caps lock led
return !!(GetCurrentKeyModifiers() & wxKeyCodeToMacModifier(key));
//else
// KeyMapByteArray keymap;
// GetKeys((BigEndianLong*)keymap);
// return !!(BitTst(keymap, (sizeof(KeyMapByteArray)*8) - iKey));
}
#if !TARGET_CARBON #if !TARGET_CARBON
void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr ) void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
{ {

View File

@@ -5057,6 +5057,18 @@ int wxCharCodeWXToMSW(int id, bool *isVirtual)
return keySym; return keySym;
} }
bool wxGetKeyState(wxKeyCode key)
{
bool bVirtual;
int vkey = wxCharCodeWXToMSW(key, &bVirtual);
//there aren't WXK_ macros for non-virtual key codes
if (bVirtual == false)
return false;
return GetKeyState(vkey) < 0;
}
wxWindow *wxGetActiveWindow() wxWindow *wxGetActiveWindow()
{ {
HWND hWnd = GetActiveWindow(); HWND hWnd = GetActiveWindow();

View File

@@ -77,6 +77,7 @@ public:
XFlush(m_display); XFlush(m_display);
XSetErrorHandler(m_old); XSetErrorHandler(m_old);
} }
private: private:
Display *m_display; Display *m_display;
int (*m_old)(Display*, XErrorEvent *); int (*m_old)(Display*, XErrorEvent *);
@@ -505,5 +506,27 @@ void wxSetFullScreenStateX11(WXDisplay* display, WXWindow rootWindow,
} }
} }
bool wxGetKeyState(wxKeyCode key)
{
Display *pDisplay = wxApp::GetDisplay();
int iKey = wxCharCodeWXToX(key);
int iKeyMask = 0;
Window wDummy1, wDummy2;
int iDummy3, iDummy4, iDummy5, iDummy6;
unsigned int iMask;
XModifierKeymap* map = XGetModifierMapping(pDisplay);
KeyCode keyCode = XKeysymToKeycode(pDisplay,iKey);
if(keyCode == NoSymbol) return false;
for(int i = 0; i < 8; ++i) {
if( map->modifiermap[map->max_keypermod * i] == keyCode) {
iKeyMask = 1 << i;
}
}
XQueryPointer(pDisplay, DefaultRootWindow(pDisplay), &wDummy1, &wDummy2,
&iDummy3, &iDummy4, &iDummy5, &iDummy6, &iMask );
XFreeModifiermap(map);
return (iMask & iKeyMask) != 0;
}
#endif #endif