-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyInput.cpp
38 lines (35 loc) · 1.05 KB
/
keyInput.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
#ifndef INPUT
#include <windows.h>
#endif
// int main() {
// cout << "pressing A\n";
// INPUT Input = { 0 };
// Input.type = INPUT_KEYBOARD;
// Input.ki.wVk = VkKeyScanA('a');
// SendInput(1, &Input, sizeof(Input));
// ZeroMemory(&Input, sizeof(Input));
// Input.ki.dwFlags = KEYEVENTF_KEYUP;
// SendInput(1, &Input, sizeof(Input));
// }
void pressKey(char key) {//press and don't release
INPUT Input = {0};
Input.type=INPUT_KEYBOARD;
Input.ki.wVk = VkKeyScanA(key);
SendInput(1,&Input,sizeof(Input));
}
void releaseKey(char key) {//release key
INPUT Input = {0};
Input.type=INPUT_KEYBOARD;
Input.ki.wVk = VkKeyScanA(key);
Input.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &Input, sizeof(Input));
}
void tapKey(char key) {//press and release key
INPUT Input = { 0 };
Input.type = INPUT_KEYBOARD;
Input.ki.wVk = VkKeyScanA(key);
SendInput(1, &Input, sizeof(Input));
ZeroMemory(&Input, sizeof(Input));
Input.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &Input, sizeof(Input));
}