diff options
| author | daoge_cmd <3523206925@qq.com> | 2026-03-01 18:50:55 +0800 |
|---|---|---|
| committer | daoge_cmd <3523206925@qq.com> | 2026-03-01 19:20:41 +0800 |
| commit | bdef1f9412d21757bc4a21ed905daff32fd0df27 (patch) | |
| tree | 26f8aad48a60a67b8e3c61ac94005456427716a4 /Minecraft.Client/Windows64/KeyboardMouseInput.h | |
| parent | 9af787692e3925d70c9f29eca3c47bdb7479d076 (diff) | |
feat: add support for keyboard and mouse input
Diffstat (limited to 'Minecraft.Client/Windows64/KeyboardMouseInput.h')
| -rw-r--r-- | Minecraft.Client/Windows64/KeyboardMouseInput.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/Minecraft.Client/Windows64/KeyboardMouseInput.h b/Minecraft.Client/Windows64/KeyboardMouseInput.h new file mode 100644 index 00000000..722c9f3d --- /dev/null +++ b/Minecraft.Client/Windows64/KeyboardMouseInput.h @@ -0,0 +1,76 @@ +#pragma once + +#ifdef _WINDOWS64 + +#include <windows.h> + +// HID usage page and usage for raw input registration +#ifndef HID_USAGE_PAGE_GENERIC +#define HID_USAGE_PAGE_GENERIC ((USHORT)0x01) +#endif +#ifndef HID_USAGE_GENERIC_MOUSE +#define HID_USAGE_GENERIC_MOUSE ((USHORT)0x02) +#endif + +class KeyboardMouseInput +{ +public: + KeyboardMouseInput(); + ~KeyboardMouseInput(); + + void Init(HWND hWnd); + void Tick(); + void EndFrame(); + + // Called from WndProc + void OnKeyDown(WPARAM vk); + void OnKeyUp(WPARAM vk); + void OnRawMouseInput(LPARAM lParam); + void OnMouseButton(int button, bool down); + void OnMouseWheel(int delta); + void ClearAllState(); + + // Key state queries (call after Tick) + bool IsKeyDown(int vk) const; + bool IsKeyPressed(int vk) const; + bool IsKeyReleased(int vk) const; + + // Mouse button queries: 0=left, 1=right, 2=middle + bool IsMouseDown(int btn) const; + bool IsMousePressed(int btn) const; + bool IsMouseReleased(int btn) const; + + // Mouse deltas (consumed each Tick) + float GetMouseDeltaX() const; + float GetMouseDeltaY() const; + int GetScrollDelta() const; + + // Mouse capture for FPS look + void SetCapture(bool capture); + bool IsCaptured() const; + +private: + void CenterCursor(); + + bool m_keyState[256]; + bool m_keyStatePrev[256]; + + bool m_mouseButtons[3]; + bool m_mouseButtonsPrev[3]; + + float m_mouseDeltaX; + float m_mouseDeltaY; + float m_mouseDeltaXAccum; + float m_mouseDeltaYAccum; + + int m_scrollDelta; + int m_scrollDeltaAccum; + + bool m_captured; + HWND m_hWnd; + bool m_initialized; +}; + +extern KeyboardMouseInput KMInput; + +#endif // _WINDOWS64 |
