Files
4JLibs/4J_Input/Windows64/INP_Keyboard.h
T
2026-08-13 09:09:09 +03:00

124 lines
3.8 KiB
C++

#pragma once
/*
MIT License
Copyright (c) 2026 Patoke
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "4J_Input.h"
void ClearGlobalText();
uint16_t *GetGlobalText();
void SeedEditBox();
class CKeyboard
{
public:
CKeyboard();
enum EKeyboardProcessState
{
};
struct SKeyboardInfo
{
};
void Init();
void Tick();
void OnKeyDown(int vkCode);
void OnKeyUp(int vkCode);
void OnChar(wchar_t ch);
void OnMouseMove(int x, int y);
void OnRawMouseDelta(int dx, int dy);
void OnLButtonDown(int x, int y);
void OnLButtonUp(int x, int y);
void OnRButtonDown(int x, int y);
void OnRButtonUp(int x, int y);
void OnMButtonDown(int x, int y);
void OnMButtonUp(int x, int y);
void OnMouseWheel(int delta, int x, int y);
bool IsKeyDown(int vkCode) const;
bool IsKeyPressed(int vkCode) const;
bool IsKeyReleased(int vkCode) const;
int GetMouseX() const { return m_mouseX; }
int GetMouseY() const { return m_mouseY; }
int GetRawMouseX() const { return m_mouseDeltaX; }
int GetRawMouseY() const { return m_mouseDeltaY; }
bool IsLButtonDown() const { return m_lButtonCurr; }
bool IsLButtonPressed() const { return m_lButtonCurr && !m_lButtonPrev; }
bool IsLButtonReleased() const { return !m_lButtonCurr && m_lButtonPrev; }
bool IsRButtonDown() const { return m_rButtonCurr; }
bool IsRButtonPressed() const { return m_rButtonCurr && !m_rButtonPrev; }
bool IsRButtonReleased() const { return !m_rButtonCurr && m_rButtonPrev; }
int GetMouseWheelDelta() const { return m_mouseWheel; }
wchar_t GetLastChar() const { return m_charCount > 0 ? m_charBuffer[0] : 0; }
bool HasChar() const { return m_charCount > 0; }
int GetCharCount() const { return m_charCount; }
wchar_t GetChar(int index) const { return (index >= 0 && index < m_charCount) ? m_charBuffer[index] : 0; }
void SetMouseCaptured(bool captured);
void SetWindowFocused(bool focused);
bool IsMouseCaptured() const { return m_mouseCaptured; }
void SetMousePos(int x, int y) { m_mouseX = x; m_mouseY = y; }
EKeyboardResult RequestKeyboard(LPCWSTR Title, LPCWSTR Text, DWORD dwPad, UINT uiMaxChars, int (*Func)(LPVOID, const bool), LPVOID lpParam,
C_4JInput::EKeyboardMode eMode);
void GetText(uint16_t *UTF16String);
BYTE gap0[0x68];
private:
static const int MAX_KEYS = 256;
static const int MAX_CHARS_PER_FRAME = 32;
bool m_keysPrev[MAX_KEYS];
bool m_keysCurr[MAX_KEYS];
int m_mouseX, m_mouseY;
bool m_lButtonPrev, m_lButtonCurr;
bool m_rButtonPrev, m_rButtonCurr;
bool m_mButtonPrev, m_mButtonCurr;
int m_mouseWheel;
wchar_t m_charBuffer[MAX_CHARS_PER_FRAME];
int m_charCount;
bool m_windowFocused;
bool m_mouseCaptured;
int m_mouseDeltaX, m_mouseDeltaY;
int m_mouseDeltaAccumX, m_mouseDeltaAccumY;
wchar_t m_chrText[128];
LPVOID m_lParam;
int (*m_onInput)(LPVOID, LPCWSTR);
};