// Copyright (c) Microsoft Corporation // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. #pragma once #include #include #include #include #include "ModuleLoader.h" /// /// Manages hotkey registration using RegisterHotKey API /// class HotkeyManager { public: HotkeyManager(); ~HotkeyManager(); // Prevent copying HotkeyManager(const HotkeyManager&) = delete; HotkeyManager& operator=(const HotkeyManager&) = delete; /// /// Register all hotkeys from a module /// /// Module to get hotkeys from /// True if at least one hotkey was registered bool RegisterModuleHotkeys(ModuleLoader& moduleLoader); /// /// Unregister all hotkeys /// void UnregisterAll(); /// /// Handle a WM_HOTKEY message /// /// ID from the WM_HOTKEY message /// Module to trigger the hotkey on /// True if the hotkey was handled bool HandleHotkey(int hotkeyId, ModuleLoader& moduleLoader); /// /// Get the number of registered hotkeys /// /// Number of registered hotkeys size_t GetRegisteredCount() const { return m_registeredHotkeys.size() + (m_hotkeyExRegistered ? 1 : 0); } /// /// Print registered hotkeys to console /// void PrintHotkeys() const; private: struct HotkeyInfo { int id = 0; size_t moduleHotkeyId = 0; UINT modifiers = 0; UINT vkCode = 0; std::wstring description; }; std::vector m_registeredHotkeys; int m_nextHotkeyId; bool m_hotkeyExRegistered; int m_hotkeyExId; /// /// Convert modifier bools to RegisterHotKey modifiers /// UINT ConvertModifiers(bool win, bool ctrl, bool alt, bool shift) const; /// /// Get a string representation of modifiers /// std::wstring ModifiersToString(UINT modifiers) const; /// /// Get a string representation of a virtual key code /// std::wstring VKeyToString(UINT vkCode) const; };