-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cpp
149 lines (121 loc) · 3.08 KB
/
Main.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
* @file Main.cpp
* @author ulynaxes
*
* @brief Перехватчик нажатий кнопок, который меняет их значения.
* з -> Z
* о -> O
* в -> V
*
* @version 1.0
* @date 2022-08-05
*
* @copyright Copyright (c) 2022
*
*/
#include <stdio.h>
#include <tchar.h>
#include <wchar.h>
// CPP библиотека.
#include <iostream>
// Библиотеки нужные для работы с windows.
#include <Windows.h>
#include <winuser.h>
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setwindowshookexa
HHOOK hHook {
NULL
};
int shift_active()
{
return GetKeyState(VK_LSHIFT) < 0 || GetKeyState(VK_RSHIFT) < 0;
}
int capital_active()
{
return (GetKeyState(VK_CAPITAL) & 1) == 1;
}
//**********************************************************************
//
// 0x5A = 'Z'
// 0x4F = 'O'
// 0x56 = 'V'
//**********************************************************************
void SendZ() {
INPUT inputs[1] = {};
ZeroMemory(inputs, sizeof(inputs));
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wVk = 0x5A;
UINT uSent = SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT));
}
void SendO() {
INPUT inputs[1] = {};
ZeroMemory(inputs, sizeof(inputs));
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wVk = 0x4F;
UINT uSent = SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT));
}
void SendV() {
INPUT inputs[1] = {};
ZeroMemory(inputs, sizeof(inputs));
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wVk = 0x56;
UINT uSent = SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT));
}
void ShowDesktop()
{
INPUT inputs[4] = {};
ZeroMemory(inputs, sizeof(inputs));
inputs[0].type = INPUT_KEYBOARD;
inputs[0].ki.wVk = VK_LWIN;
inputs[1].type = INPUT_KEYBOARD;
inputs[1].ki.wVk = VK_LWIN;
UINT uSent = SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT));
if (uSent != ARRAYSIZE(inputs))
{
//std::cout << (L"SendInput failed: 0x%x\n", HRESULT_FROM_WIN32(GetLastError())) << std::endl;
}
}
//https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/ms644984(v=vs.85)?redirectedfrom=MSDN
LRESULT CALLBACK keyboard_hook(const int code, const WPARAM wParam, const LPARAM lParam)
{
KBDLLHOOKSTRUCT *s = reinterpret_cast<KBDLLHOOKSTRUCT *>(lParam);
switch (wParam)
{
case WM_KEYDOWN:
char c = MapVirtualKey(s->vkCode, MAPVK_VK_TO_CHAR);
// ShowDesktop();
if (c == 'p' || c == 'P' || c == 'з' || c == 'З')
{
SendZ();
break;
}
if (c == 'j' || c == 'J' || c == 'о' || c == 'О')
{
SendO();
break;
}
if (c == 'd' || c == 'D' || c == 'в' || c == 'В')
{
SendV();
break;
}
std::cout << c << std::endl;
break;
}
return CallNextHookEx(hHook, code, wParam, lParam);
}
int main(int argc, char* argv[])
{
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, keyboard_hook, 0, 0);
if (hHook == NULL)
{
std::cout << "Keyboard hook failed!" << std::endl;
}
MSG message;
while (GetMessage(&message, NULL, NULL, NULL) > 0)
{
TranslateMessage(&message);
DispatchMessage(&message);
}
UnhookWindowsHookEx(hHook);
return 0;
}