std_keyboard.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "precomp_wasabi_bfc.h"
  2. #include "std_keyboard.h"
  3. int Std::keyDown(int code)
  4. {
  5. #ifdef WIN32
  6. return !!(GetKeyState(code) & 0x8000);
  7. #elif defined(LINUX)
  8. if ( code == MK_RBUTTON || code == MK_LBUTTON ) {
  9. Window t1, t2;
  10. int rx, ry, wx, wy;
  11. unsigned int buttons;
  12. XQueryPointer( Linux::getDisplay(), Linux::RootWin(), &t1, &t2,
  13. &rx, &ry, &wx, &wy, &buttons );
  14. if ( code == MK_RBUTTON )
  15. return buttons & Button3Mask;
  16. else
  17. return buttons & Button1Mask;
  18. }
  19. int code1 = XKeysymToKeycode( Linux::getDisplay(), code & 0xFFFF );
  20. int code2 = XKeysymToKeycode( Linux::getDisplay(), (code>>16) & 0xFFFF );
  21. char keys_return[32] = {0};
  22. XQueryKeymap( Linux::getDisplay(), keys_return );
  23. if ( code1 && code2 )
  24. return (keys_return[ (code1 >> 3) & 31 ] & (1 << (code1 & 7))) ||
  25. (keys_return[ (code2 >> 3) & 31 ] & (1 << (code2 & 7)));
  26. return (keys_return[ (code1 >> 3) & 31 ] & (1 << (code1 & 7)));
  27. #else
  28. return 0;
  29. #warning port me!
  30. #endif
  31. }
  32. // TODO: add async flag to be able to choose between GetKeyState/GetAsyncKeyState (win32) GetCurrentKeyModifiers/GetCurrentEventkeyModifiers (mac)
  33. bool Std::keyModifier(int code)
  34. {
  35. #ifdef WIN32
  36. return !!(GetKeyState(code) & 0x8000);
  37. #elif defined(__APPLE__)
  38. return GetCurrentKeyModifiers() & code;
  39. #elif defined(LINUX)
  40. #error port me
  41. #endif
  42. }