1
0

InputHandler.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * InputHandler.h
  3. * --------------
  4. * Purpose: Implementation of keyboard input handling, keymap loading, ...
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #pragma once
  10. #include "openmpt/all/BuildSettings.hpp"
  11. #include "CommandSet.h"
  12. OPENMPT_NAMESPACE_BEGIN
  13. // Hook codes
  14. enum
  15. {
  16. HC_MIDI = 0x8000,
  17. };
  18. class CInputHandler
  19. {
  20. protected:
  21. CWnd *m_pMainFrm;
  22. KeyMap m_keyMap;
  23. FlagSet<Modifiers> m_modifierMask = ModNone;
  24. int m_bypassCount = 0;
  25. bool m_bInterceptWindowsKeys : 1, m_bInterceptNumLock : 1, m_bInterceptCapsLock : 1, m_bInterceptScrollLock : 1;
  26. public:
  27. std::unique_ptr<CCommandSet> m_activeCommandSet;
  28. std::array<CommandID, 10> m_lastCommands;
  29. size_t m_lastCommandPos = 0;
  30. public:
  31. CInputHandler(CWnd *mainframe);
  32. CommandID GeneralKeyEvent(InputTargetContext context, int code, WPARAM wParam , LPARAM lParam);
  33. CommandID KeyEvent(InputTargetContext context, UINT &nChar, UINT &nRepCnt, UINT &nFlags, KeyEventType keyEventType, CWnd *pSourceWnd = nullptr);
  34. static KeyEventType GetKeyEventType(UINT nFlags);
  35. bool IsKeyPressHandledByTextBox(DWORD wparam, HWND hWnd) const;
  36. CommandID HandleMIDIMessage(InputTargetContext context, uint32 message);
  37. int GetKeyListSize(CommandID cmd) const;
  38. protected:
  39. void LogModifiers();
  40. bool CatchModifierChange(WPARAM wParam, KeyEventType keyEventType, int scancode);
  41. bool InterceptSpecialKeys(UINT nChar, UINT nFlags, bool generateMsg);
  42. void SetupSpecialKeyInterception();
  43. CommandID SendCommands(CWnd *wnd, const KeyMapRange &cmd);
  44. public:
  45. bool ShiftPressed() const;
  46. bool SelectionPressed() const;
  47. bool CtrlPressed() const;
  48. bool AltPressed() const;
  49. bool IsBypassed() const;
  50. void Bypass(bool);
  51. FlagSet<Modifiers> GetModifierMask() const;
  52. void SetModifierMask(FlagSet<Modifiers> mask);
  53. CString GetKeyTextFromCommand(CommandID c, const TCHAR *prependText = nullptr) const;
  54. CString GetMenuText(UINT id) const;
  55. void UpdateMainMenu();
  56. void SetNewCommandSet(const CCommandSet *newSet);
  57. bool SetEffectLetters(const CModSpecifications &modSpecs);
  58. };
  59. // RAII object for temporarily bypassing the input handler
  60. class BypassInputHandler
  61. {
  62. private:
  63. bool bypassed = false;
  64. public:
  65. BypassInputHandler();
  66. ~BypassInputHandler();
  67. };
  68. OPENMPT_NAMESPACE_END