Input.h
1 #pragma once 2 3 #include <common/logger/logger.h> 4 #include <common/utils/winapi_error.h> 5 #include <keyboardmanager/common/Helpers.h> 6 #include <keyboardmanager/common/InputInterface.h> 7 8 namespace KeyboardManagerInput 9 { 10 // Class used to wrap keyboard input library methods 11 class Input : public InputInterface 12 { 13 public: 14 // Function to simulate input 15 void SendVirtualInput(const std::vector<INPUT>& inputs) 16 { 17 std::vector<INPUT> copy = inputs; 18 UINT eventCount = SendInput(static_cast<UINT>(copy.size()), copy.data(), sizeof(INPUT)); 19 if (eventCount != copy.size()) 20 { 21 Logger::error( 22 L"Failed to send input events. {}", 23 get_last_error_or_default(GetLastError())); 24 } 25 } 26 27 // Function to get the state of a particular key 28 bool GetVirtualKeyState(int key) 29 { 30 return (GetAsyncKeyState(key) & 0x8000); 31 } 32 33 // Function to get the foreground process name 34 void GetForegroundProcess(_Out_ std::wstring& foregroundProcess) 35 { 36 foregroundProcess = Helpers::GetCurrentApplication(false); 37 } 38 }; 39 }