diff options
Diffstat (limited to 'Src/Wasabi/bfc/std_keyboard.cpp')
-rw-r--r-- | Src/Wasabi/bfc/std_keyboard.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/Src/Wasabi/bfc/std_keyboard.cpp b/Src/Wasabi/bfc/std_keyboard.cpp new file mode 100644 index 00000000..aa5707dc --- /dev/null +++ b/Src/Wasabi/bfc/std_keyboard.cpp @@ -0,0 +1,51 @@ +#include "precomp_wasabi_bfc.h" +#include "std_keyboard.h" + +int Std::keyDown(int code) +{ +#ifdef WIN32 + return !!(GetKeyState(code) & 0x8000); +#elif defined(LINUX) + if ( code == MK_RBUTTON || code == MK_LBUTTON ) { + Window t1, t2; + int rx, ry, wx, wy; + unsigned int buttons; + + XQueryPointer( Linux::getDisplay(), Linux::RootWin(), &t1, &t2, + &rx, &ry, &wx, &wy, &buttons ); + + if ( code == MK_RBUTTON ) + return buttons & Button3Mask; + else + return buttons & Button1Mask; + } + + int code1 = XKeysymToKeycode( Linux::getDisplay(), code & 0xFFFF ); + int code2 = XKeysymToKeycode( Linux::getDisplay(), (code>>16) & 0xFFFF ); + + char keys_return[32] = {0}; + XQueryKeymap( Linux::getDisplay(), keys_return ); + + if ( code1 && code2 ) + return (keys_return[ (code1 >> 3) & 31 ] & (1 << (code1 & 7))) || + (keys_return[ (code2 >> 3) & 31 ] & (1 << (code2 & 7))); + + return (keys_return[ (code1 >> 3) & 31 ] & (1 << (code1 & 7))); +#else + return 0; +#warning port me! +#endif +} + +// TODO: add async flag to be able to choose between GetKeyState/GetAsyncKeyState (win32) GetCurrentKeyModifiers/GetCurrentEventkeyModifiers (mac) +bool Std::keyModifier(int code) +{ +#ifdef WIN32 + return !!(GetKeyState(code) & 0x8000); +#elif defined(__APPLE__) + return GetCurrentKeyModifiers() & code; +#elif defined(LINUX) +#error port me +#endif +} + |