-
Notifications
You must be signed in to change notification settings - Fork 12
/
WinLowLevel.cpp
64 lines (56 loc) · 1.63 KB
/
WinLowLevel.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "WinLowLevel.h"
#include "../TrackpadDLL/TrackpadDLL.h"
#include <Windows.h>
#include <iostream>
#pragma comment(lib, "TrackpadDLL.lib")
void WinLowLevel::ForceOnTop() {
HWND hwnd = GetActiveWindow();
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
}
void WinLowLevel::MakeMessage(const char* msg) {
HWND hwnd = GetActiveWindow();
MessageBox(hwnd, msg, "ERROR", MB_OK);
}
void WinLowLevel::CreateHook() {
//Register keyboard Hook
HWND hwnd = GetActiveWindow();
InstallHook(hwnd);
}
void WinLowLevel::DestroyHook() {
//Remove the keyboard Hook
UninstallHook();
}
void WinLowLevel::Move(int dx, int dy) {
INPUT input = { 0 };
::ZeroMemory(&input, sizeof(INPUT));
input.type = INPUT_MOUSE;
input.mi.dwFlags = MOUSEEVENTF_MOVE;
input.mi.dx = (LONG)dx;
input.mi.dy = (LONG)dy;
::SendInput(1, &input, sizeof(INPUT));
}
void WinLowLevel::Click(bool pressed) {
INPUT input = { 0 };
::ZeroMemory(&input, sizeof(INPUT));
input.type = INPUT_MOUSE;
input.mi.dwFlags = (pressed ? MOUSEEVENTF_LEFTDOWN : MOUSEEVENTF_LEFTUP);
::SendInput(1, &input, sizeof(INPUT));
}
void WinLowLevel::Scroll(int dx, int dy) {
if (dy != 0) {
INPUT input = { 0 };
::ZeroMemory(&input, sizeof(INPUT));
input.type = INPUT_MOUSE;
input.mi.dwFlags = MOUSEEVENTF_WHEEL;
input.mi.mouseData = (LONG)dy;
::SendInput(1, &input, sizeof(INPUT));
}
if (dx != 0) {
INPUT input = { 0 };
::ZeroMemory(&input, sizeof(INPUT));
input.type = INPUT_MOUSE;
input.mi.dwFlags = MOUSEEVENTF_HWHEEL;
input.mi.mouseData = (LONG)dx;
::SendInput(1, &input, sizeof(INPUT));
}
}