#pragma once #import #include #include // Windows message constants (for parsing server commands) #define WM_MOUSEMOVE 0x0200 #define WM_LBUTTONDOWN 0x0201 #define WM_LBUTTONUP 0x0202 #define WM_LBUTTONDBLCLK 0x0203 #define WM_RBUTTONDOWN 0x0204 #define WM_RBUTTONUP 0x0205 #define WM_RBUTTONDBLCLK 0x0206 #define WM_MBUTTONDOWN 0x0207 #define WM_MBUTTONUP 0x0208 #define WM_MBUTTONDBLCLK 0x0209 #define WM_MOUSEWHEEL 0x020A #define WM_KEYDOWN 0x0100 #define WM_KEYUP 0x0101 #define WM_SYSKEYDOWN 0x0104 #define WM_SYSKEYUP 0x0105 // Windows wheel delta extraction #define GET_WHEEL_DELTA_WPARAM(wParam) ((short)((wParam) >> 16)) // MSG64 structure (compatible with Windows/Linux) #pragma pack(push, 1) struct MSG64_MAC { uint64_t hwnd; uint64_t message; uint64_t wParam; uint64_t lParam; uint64_t time; int32_t pt_x; int32_t pt_y; }; #pragma pack(pop) class InputHandler { public: InputHandler(); ~InputHandler(); // Initialize (checks accessibility permission) bool init(); // Handle input event from server void handleInputEvent(const MSG64_MAC* msg); // Check if accessibility permission is available bool hasAccessibilityPermission() const { return m_hasPermission; } private: // Mouse event helpers void handleMouseMove(int x, int y); void handleMouseButton(CGMouseButton button, bool down, int x, int y); void handleMouseDoubleClick(CGMouseButton button, int x, int y); void handleMouseWheel(int delta); // Keyboard event helpers void handleKeyEvent(uint32_t vkCode, bool down); // Convert Windows VK code to macOS key code static CGKeyCode vkToMacKeyCode(uint32_t vk); private: std::atomic m_hasPermission{false}; std::atomic m_warningLogged{false}; // Track button states for CGEvent (atomic for thread safety) CGPoint m_lastMousePos; std::atomic m_leftButtonDown{false}; std::atomic m_rightButtonDown{false}; std::atomic m_middleButtonDown{false}; // Track modifier key states for proper key event handling std::atomic m_modifierFlags{0}; };