/ src / modules / keyboardmanager / KeyboardManagerEngineLibrary / KeyboardEventHandlers.h
KeyboardEventHandlers.h
 1  #pragma once
 2  
 3  #include <common/hooks/LowlevelKeyboardEvent.h>
 4  #include "State.h"
 5  
 6  namespace KeyboardManagerInput
 7  {
 8      class InputInterface;
 9  }
10  
11  namespace KeyboardEventHandlers
12  {
13  
14      struct ResetChordsResults
15      {
16          bool CurrentKeyIsModifierKey;
17          bool AnyChordStarted;
18      };
19  
20      // Function to handle a single key remap
21      intptr_t HandleSingleKeyRemapEvent(KeyboardManagerInput::InputInterface& ii, LowlevelKeyboardEvent* data, State& state) noexcept;
22  
23      /* This feature has not been enabled (code from proof of concept stage)
24          // Function to change a key's behavior from toggle to modifier
25          __declspec(dllexport) intptr_t HandleSingleKeyToggleToModEvent(InputInterface& ii, LowlevelKeyboardEvent* data, State& state) noexcept;
26      */
27  
28      // Function to handle a shortcut remap
29      intptr_t HandleShortcutRemapEvent(KeyboardManagerInput::InputInterface& ii, LowlevelKeyboardEvent* data, State& state, const std::optional<std::wstring>& activatedApp = std::nullopt) noexcept;
30  
31      // Function to reset chord matching
32      void ResetAllStartedChords(State& state, const std::optional<std::wstring>& activatedApp);
33  
34      // Function to reset chord matching
35      void ResetAllOtherStartedChords(State& state, const std::optional<std::wstring>& activatedApp, DWORD keyToKeep);
36  
37      std::wstring URL_encode(const std::wstring& value);
38  
39      std::wstring ConvertPathToURI(const std::wstring& filePath);
40  
41      // Function to reset chord matching if needed
42      ResetChordsResults ResetChordsIfNeeded(LowlevelKeyboardEvent* data, State& state, const std::optional<std::wstring>& activatedApp);
43  
44      // Function to handle (start or show) programs for shortcuts
45      void CreateOrShowProcessForShortcut(Shortcut shortcut) noexcept;
46  
47      void CloseProcessByName(const std::wstring& fileNamePart);
48  
49      void TerminateProcessesByName(const std::wstring& fileNamePart);
50  
51      void toast(winrt::param::hstring const& message1, winrt::param::hstring const& message2) noexcept;
52  
53      // Function to help FindMainWindow
54      BOOL CALLBACK EnumWindowsCallback(HWND handle, LPARAM lParam);
55  
56      // Function to help FindMainWindow
57      BOOL CALLBACK EnumWindowsCallbackAllowNonVisible(HWND handle, LPARAM lParam);
58  
59      // Function to FindMainWindow
60      HWND FindMainWindow(unsigned long process_id, const bool allowNonVisible);
61  
62      // Function to GetProcessIdByName
63      DWORD GetProcessIdByName(const std::wstring& processName);
64  
65      // Function to GetProcessesIdByName
66      std::vector<DWORD> GetProcessesIdByName(const std::wstring& processName);
67  
68      // Function to get just the file name from a fill path
69      std::wstring GetFileNameFromPath(const std::wstring& fullPath);
70  
71      // Function to find and show a running program
72      bool ShowProgram(DWORD pid, std::wstring programName, bool isNewProcess, bool minimizeIfVisible, int retryCount);
73  
74      bool HideProgram(DWORD pid, std::wstring programName, int retryCount);
75  
76      // Function to handle an os-level shortcut remap
77      intptr_t HandleOSLevelShortcutRemapEvent(KeyboardManagerInput::InputInterface& ii, LowlevelKeyboardEvent* data, State& state) noexcept;
78  
79      // Function to handle an app-specific shortcut remap
80      intptr_t HandleAppSpecificShortcutRemapEvent(KeyboardManagerInput::InputInterface& ii, LowlevelKeyboardEvent* data, State& state) noexcept;
81  
82      // Function to generate a unicode string in response to a single keypress
83      intptr_t HandleSingleKeyToTextRemapEvent(KeyboardManagerInput::InputInterface& ii, LowlevelKeyboardEvent* data, State& state);
84  
85      // Function to ensure Ctrl/Shift/Alt modifier key state is not detected as pressed down by applications which detect keys at a lower level than hooks when it is remapped for scenarios where its required
86      void ResetIfModifierKeyForLowerLevelKeyHandlers(KeyboardManagerInput::InputInterface& ii, DWORD key, DWORD target);
87  };