Changes
This commit is contained in:
+10
@@ -1,3 +1,13 @@
|
|||||||
/build
|
/build
|
||||||
/out
|
/out
|
||||||
/CMakePresets.json
|
/CMakePresets.json
|
||||||
|
/cmake-build-debug-mingw/
|
||||||
|
/cmake-build-release-mingw/
|
||||||
|
/cmake-build-release-visual-studio/
|
||||||
|
/.idea/codeStyles/codeStyleConfig.xml
|
||||||
|
/.idea/editor.xml
|
||||||
|
/.idea/HighBloodPressure.iml
|
||||||
|
/.idea/misc.xml
|
||||||
|
/.idea/modules.xml
|
||||||
|
/.idea/codeStyles/Project.xml
|
||||||
|
/.idea/vcs.xml
|
||||||
|
|||||||
@@ -263,3 +263,5 @@ InteractManager::InteractManager() {
|
|||||||
keyStatus[0xFE].name = L"OEM-Clear";
|
keyStatus[0xFE].name = L"OEM-Clear";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KeyStatus& InteractManager::getKey(const KeyBinding& binding) noexcept { return keyStatus[binding.keyCode]; }
|
||||||
|
|
||||||
|
|||||||
+49
-6
@@ -9,29 +9,72 @@
|
|||||||
struct KeyStatus {
|
struct KeyStatus {
|
||||||
String name;
|
String name;
|
||||||
unsigned int pressTimes = 0;
|
unsigned int pressTimes = 0;
|
||||||
bool isPressed = false;
|
bool pressed = false;
|
||||||
bool notDealt = false;
|
bool notDealt = false;
|
||||||
|
|
||||||
[[nodiscard]] String toString() const noexcept {
|
[[nodiscard]] bool isPressed() const noexcept { return pressed; }
|
||||||
return L"name: " + name + L" pressTimes: " + std::to_wstring(pressTimes) + L" isPressed";
|
[[nodiscard]] unsigned int wasPressed() const noexcept { return pressTimes; }
|
||||||
|
|
||||||
|
void deals() noexcept {
|
||||||
|
notDealt = false;
|
||||||
|
pressTimes = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] String toString() const noexcept { return L"KeyStatus: { name = \"" + name + L"\"; pressTimes = " + std::to_wstring(pressTimes) + L"; pressed = " + (pressed ? L"true }" : L"false }"); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct KeyBinding;
|
||||||
|
|
||||||
class InteractManager {
|
class InteractManager {
|
||||||
KeyStatus keyStatus[256];
|
KeyStatus keyStatus[256];
|
||||||
|
int mouseX = 0, mouseY = 0;
|
||||||
|
int mouseWheel = 0;
|
||||||
|
int rebindResult = 0;
|
||||||
|
bool rebinding = false;
|
||||||
|
bool inWindow = false; // 鼠标是否在窗口内部
|
||||||
public:
|
public:
|
||||||
explicit InteractManager();
|
explicit InteractManager();
|
||||||
|
|
||||||
void update(const int keyCode, const bool isPressed) noexcept {
|
void update(const int keyCode, const bool isPressed) noexcept {
|
||||||
if (keyCode >= 256) return;
|
if (keyCode >= 256) return;
|
||||||
keyStatus[keyCode].isPressed = isPressed;
|
if (rebinding) {
|
||||||
|
rebindResult = keyCode;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
keyStatus[keyCode].pressed = isPressed;
|
||||||
if (isPressed) {
|
if (isPressed) {
|
||||||
keyStatus[keyCode].pressTimes++;
|
keyStatus[keyCode].pressTimes++;
|
||||||
keyStatus[keyCode].notDealt = true;
|
keyStatus[keyCode].notDealt = true;
|
||||||
}
|
}
|
||||||
std::wcout << keyStatus[keyCode].toString() << std::endl;
|
}
|
||||||
|
|
||||||
|
void updateMouse(const int x, const int y) noexcept {
|
||||||
|
mouseX = x;
|
||||||
|
mouseY = y;
|
||||||
|
std::wcout << x << " " << y << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateWheel(const int wheel) noexcept { mouseWheel += wheel; }
|
||||||
|
|
||||||
|
[[nodiscard]] int getMouseX() const noexcept { return mouseX; }
|
||||||
|
[[nodiscard]] int getMouseY() const noexcept { return mouseY; }
|
||||||
|
[[nodiscard]] int getMouseWheel() const noexcept { return mouseWheel; }
|
||||||
|
KeyStatus& getKey(const int keyCode) noexcept { return keyStatus[keyCode]; }
|
||||||
|
KeyStatus& getKey(const KeyBinding& binding) noexcept;
|
||||||
|
|
||||||
|
int dealMouseWheel() noexcept {
|
||||||
|
const int ret = mouseWheel;
|
||||||
|
mouseWheel = 0;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inline static InteractManager interactManager = InteractManager();
|
inline static InteractManager interactManager = InteractManager();
|
||||||
|
|
||||||
|
struct KeyBinding {
|
||||||
|
String id;
|
||||||
|
int keyCode;
|
||||||
|
[[nodiscard]] bool isPressed() const noexcept { return interactManager.getKey(keyCode).isPressed(); }
|
||||||
|
[[nodiscard]] unsigned int wasPressed() const noexcept { return interactManager.getKey(keyCode).wasPressed(); }
|
||||||
|
void deals() const noexcept { interactManager.getKey(keyCode).deals(); }
|
||||||
|
};
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
using wchar = wchar_t;
|
||||||
|
using QWORD = unsigned long long int;
|
||||||
using String = std::wstring;
|
using String = std::wstring;
|
||||||
template<typename K, typename V, typename Cmp = std::less<K>, typename Alloc = std::allocator<std::pair<const K, V>>> using Map = std::map<K, V, Cmp, Alloc>;
|
template<typename K, typename V, typename Cmp = std::less<K>, typename Alloc = std::allocator<std::pair<const K, V>>> using Map = std::map<K, V, Cmp, Alloc>;
|
||||||
|
|
||||||
@@ -28,3 +30,16 @@ template<typename K, typename V, typename Cmp = std::less<K>, typename Alloc = s
|
|||||||
|
|
||||||
#define NOMINMAX
|
#define NOMINMAX
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
#include <Windowsx.h>
|
||||||
|
#include <minwindef.h>
|
||||||
|
#include <windef.h>
|
||||||
|
#include <wingdi.h>
|
||||||
|
#include <WinUser.h>
|
||||||
|
#include <Uxtheme.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <dwmapi.h>
|
||||||
|
|
||||||
|
#pragma comment(lib, "ws2_32.lib")
|
||||||
|
#pragma comment(lib, "dwmapi.lib")
|
||||||
|
#pragma comment(lib, "Uxtheme.lib")
|
||||||
|
#pragma comment(lib, "winmm.lib")
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ inline BOOL NewProcess(const String& cmdline) noexcept {
|
|||||||
return CreateProcessW(nullptr, const_cast<wchar*>(cmdline.c_str()), nullptr, nullptr, 0, 0, nullptr, nullptr, &si, &pi);
|
return CreateProcessW(nullptr, const_cast<wchar*>(cmdline.c_str()), nullptr, nullptr, 0, 0, nullptr, nullptr, &si, &pi);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline HRESULT RemoveDefaultCaption(const HWND hWnd, const MARGINS* p) noexcept { return DwmExtendFrameIntoClientArea(hWnd, p); }
|
inline HRESULT RemoveDefaultCaption(HWND const hWnd, const MARGINS* p) noexcept { return DwmExtendFrameIntoClientArea(hWnd, p); }
|
||||||
|
|
||||||
inline void ShowConsoleIO() noexcept {
|
inline void ShowConsoleIO() noexcept {
|
||||||
AllocConsole();
|
AllocConsole();
|
||||||
|
|||||||
@@ -1,13 +1,4 @@
|
|||||||
|
|
||||||
#include <Windows.h>
|
|
||||||
#include <minwindef.h>
|
|
||||||
#include <windef.h>
|
|
||||||
#include <wingdi.h>
|
|
||||||
#include <winuser.h>
|
|
||||||
#include <Uxtheme.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <dwmapi.h>
|
|
||||||
|
|
||||||
#include "hbp.h"
|
#include "hbp.h"
|
||||||
#include "InteractManager.h"
|
#include "InteractManager.h"
|
||||||
|
|
||||||
@@ -20,6 +11,20 @@ LRESULT __stdcall WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
|||||||
EndPaint(hwnd, &ps);
|
EndPaint(hwnd, &ps);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
_LIKELY
|
||||||
|
case WM_NCHITTEST: {
|
||||||
|
LRESULT lr = 0;
|
||||||
|
BOOL r = DwmDefWindowProc(hwnd, uMsg, wParam, lParam, &lr);
|
||||||
|
return HTCLIENT;
|
||||||
|
}
|
||||||
|
case WM_KEYDOWN: interactManager.update(static_cast<int>(wParam), true);
|
||||||
|
break;
|
||||||
|
case WM_KEYUP: interactManager.update(static_cast<int>(wParam), false);
|
||||||
|
break;
|
||||||
|
case WM_SYSKEYDOWN: interactManager.update(static_cast<int>(wParam), true);
|
||||||
|
break;
|
||||||
|
case WM_SYSKEYUP: interactManager.update(static_cast<int>(wParam), false);
|
||||||
|
break;
|
||||||
case WM_LBUTTONDOWN: interactManager.update(VK_LBUTTON, true);
|
case WM_LBUTTONDOWN: interactManager.update(VK_LBUTTON, true);
|
||||||
break;
|
break;
|
||||||
case WM_RBUTTONDOWN: interactManager.update(VK_RBUTTON, true);
|
case WM_RBUTTONDOWN: interactManager.update(VK_RBUTTON, true);
|
||||||
@@ -28,17 +33,14 @@ LRESULT __stdcall WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
|||||||
break;
|
break;
|
||||||
case WM_RBUTTONUP: interactManager.update(VK_RBUTTON, false);
|
case WM_RBUTTONUP: interactManager.update(VK_RBUTTON, false);
|
||||||
break;
|
break;
|
||||||
_LIKELY
|
case WM_MOUSEMOVE: interactManager.updateMouse(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
|
||||||
case WM_NCHITTEST: {
|
break;
|
||||||
LRESULT lr = 0;
|
case WM_MBUTTONDOWN: if (wParam & 0x10) interactManager.update(VK_MBUTTON, true);
|
||||||
BOOL r = DwmDefWindowProc(hwnd, uMsg, wParam, lParam, &lr);
|
|
||||||
return lr;
|
|
||||||
}
|
|
||||||
case WM_MOUSEMOVE: { break; }
|
|
||||||
case WM_MBUTTONDOWN: interactManager.update(VK_MBUTTON, true);
|
|
||||||
break;
|
break;
|
||||||
case WM_MBUTTONUP: interactManager.update(VK_MBUTTON, false);
|
case WM_MBUTTONUP: interactManager.update(VK_MBUTTON, false);
|
||||||
break;
|
break;
|
||||||
|
case WM_MOUSEWHEEL: interactManager.update(VK_MBUTTON, true);
|
||||||
|
break;
|
||||||
case WM_COMMAND: std::wcout << L"WM_COMMAND" << std::endl;
|
case WM_COMMAND: std::wcout << L"WM_COMMAND" << std::endl;
|
||||||
break;
|
break;
|
||||||
case WM_DWMCOMPOSITIONCHANGED: {
|
case WM_DWMCOMPOSITIONCHANGED: {
|
||||||
@@ -60,16 +62,16 @@ LRESULT __stdcall WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case WM_SIZE: switch (wParam) {
|
case WM_SIZE: switch (wParam) {
|
||||||
case SIZE_RESTORED: break;
|
case SIZE_RESTORED:
|
||||||
case SIZE_MINIMIZED: break;
|
case SIZE_MINIMIZED:
|
||||||
case SIZE_MAXIMIZED: break;
|
case SIZE_MAXIMIZED:
|
||||||
case SIZE_MAXSHOW:
|
case SIZE_MAXSHOW:
|
||||||
case SIZE_MAXHIDE:
|
case SIZE_MAXHIDE:
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case WM_ACTIVATE: {
|
case WM_ACTIVATE: {
|
||||||
MARGINS margins{
|
constexpr MARGINS margins{
|
||||||
.cxLeftWidth = 0,
|
.cxLeftWidth = 0,
|
||||||
.cxRightWidth = 0,
|
.cxRightWidth = 0,
|
||||||
.cyTopHeight = 0,
|
.cyTopHeight = 0,
|
||||||
@@ -91,6 +93,7 @@ LRESULT __stdcall WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
|||||||
|
|
||||||
int __stdcall wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) {
|
int __stdcall wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) {
|
||||||
AllocConsole();
|
AllocConsole();
|
||||||
|
freopen("CONOUT$", "w", stdout);
|
||||||
WNDCLASSEX wc = { 0 };
|
WNDCLASSEX wc = { 0 };
|
||||||
wc.cbSize = sizeof(WNDCLASSEX);
|
wc.cbSize = sizeof(WNDCLASSEX);
|
||||||
wc.style = CS_HREDRAW | CS_VREDRAW;
|
wc.style = CS_HREDRAW | CS_VREDRAW;
|
||||||
@@ -104,6 +107,7 @@ int __stdcall wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCm
|
|||||||
wc.lpszMenuName = L"None";
|
wc.lpszMenuName = L"None";
|
||||||
wc.lpszClassName = ApplicationName.c_str();
|
wc.lpszClassName = ApplicationName.c_str();
|
||||||
if (!RegisterClassExW(&wc)) return FALSE;
|
if (!RegisterClassExW(&wc)) return FALSE;
|
||||||
|
if (!SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE)) std::wcout << L"SetProcessDpiAwarenessContext failed. LastError: " << GetLastError() << std::endl;
|
||||||
MainInstance = hInstance;
|
MainInstance = hInstance;
|
||||||
MainWindowHandle = CreateWindowExW(0, wc.lpszClassName, wc.lpszClassName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, nullptr, nullptr, hInstance, nullptr);
|
MainWindowHandle = CreateWindowExW(0, wc.lpszClassName, wc.lpszClassName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, nullptr, nullptr, hInstance, nullptr);
|
||||||
ShowWindow(MainWindowHandle, nCmdShow);
|
ShowWindow(MainWindowHandle, nCmdShow);
|
||||||
|
|||||||
Reference in New Issue
Block a user