keyboard.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*****************************************************************************
  2. * keyboard.cpp - QStarDict, a quasi-star dictionary *
  3. * Copyright (C) 2007-2019 Alexander Rodin *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License along *
  16. * with this program; if not, write to the Free Software Foundation, Inc., *
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
  18. *****************************************************************************/
  19. #include <QApplication>
  20. #include "keyboard.h"
  21. #ifdef Q_OS_WIN
  22. #include <windows.h>
  23. #include <winuser.h>
  24. namespace QStarDict
  25. {
  26. Qt::KeyboardModifiers Keyboard::activeModifiers()
  27. {
  28. Qt::KeyboardModifiers result;
  29. if (GetAsyncKeyState(VK_MENU) & 0x8000)
  30. result |= Qt::AltModifier;
  31. if (GetAsyncKeyState(VK_CONTROL) & 0x8000)
  32. result |= Qt::ControlModifier;
  33. if (GetAsyncKeyState(VK_SHIFT) & 0x8000)
  34. result |= Qt::ShiftModifier;
  35. if ((GetAsyncKeyState(VK_LWIN) & 0x8000) || (GetAsyncKeyState(VK_RWIN) & 0x8000))
  36. result |= Qt::MetaModifier;
  37. return result;
  38. }
  39. } // namespace
  40. #else
  41. namespace QStarDict
  42. {
  43. Qt::KeyboardModifiers Keyboard::activeModifiers()
  44. {
  45. return QApplication::queryKeyboardModifiers();
  46. }
  47. } // namespace
  48. #endif // Q_OS_WIN
  49. // vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab cindent textwidth=120 formatoptions=tc