MockedInput.h
1 #pragma once 2 #include <keyboardmanager/common/InputInterface.h> 3 #include <vector> 4 #include <functional> 5 6 #include <common/hooks/LowlevelKeyboardEvent.h> 7 8 namespace KeyboardManagerInput 9 { 10 // Class for mocked keyboard input 11 class MockedInput : 12 public InputInterface 13 { 14 private: 15 // Stores the states for all the keys - false for key up, and true for key down 16 std::vector<bool> keyboardState; 17 18 // Function to be executed as a low level hook. By default it is nullptr so the hook is skipped 19 std::function<intptr_t(LowlevelKeyboardEvent*)> hookProc; 20 21 // Stores the count of sendVirtualInput calls given if the condition sendVirtualInputCallCondition is satisfied 22 int sendVirtualInputCallCount = 0; 23 std::function<bool(LowlevelKeyboardEvent*)> sendVirtualInputCallCondition; 24 25 std::wstring currentProcess; 26 27 public: 28 MockedInput() 29 { 30 keyboardState.resize(256, false); 31 } 32 33 // Set the keyboard hook procedure to be tested 34 void SetHookProc(std::function<intptr_t(LowlevelKeyboardEvent*)> hookProcedure); 35 36 // Function to simulate keyboard input 37 void SendVirtualInput(const std::vector<INPUT>& inputs); 38 39 // Function to simulate keyboard hook behavior 40 intptr_t MockedKeyboardHook(LowlevelKeyboardEvent* data); 41 42 // Function to get the state of a particular key 43 bool GetVirtualKeyState(int key); 44 45 // Function to reset the mocked keyboard state 46 void ResetKeyboardState(); 47 48 // Function to set SendVirtualInput call count condition 49 void SetSendVirtualInputTestHandler(std::function<bool(LowlevelKeyboardEvent*)> condition); 50 51 // Function to get SendVirtualInput call count 52 int GetSendVirtualInputCallCount(); 53 54 // Function to get the foreground process name 55 void SetForegroundProcess(std::wstring process); 56 57 // Function to get the foreground process name 58 void GetForegroundProcess(_Out_ std::wstring& foregroundProcess); 59 }; 60 } 61