-
Notifications
You must be signed in to change notification settings - Fork 0
/
bluePoint.cpp
250 lines (234 loc) · 8.78 KB
/
bluePoint.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
// TODO: Add Input Placeholder
#include <windows.h>
HHOOK my_hook; // Keyboard hook
HINSTANCE g_hinst;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT ch1, ch2, ch3; // Store combobox values
void mediaPlay(); // Handle Media_Play_Pause event
void mediaPrev(); // Handle Media_Prev event
void mediaNext(); // Handle Media_Next event
LRESULT __stdcall k_Callback1(int Code, WPARAM wParam, LPARAM lParam) {
PKBDLLHOOKSTRUCT key = (PKBDLLHOOKSTRUCT)lParam;
if (wParam == WM_KEYDOWN && Code == HC_ACTION) {
switch (key->vkCode) {
case VK_MEDIA_PLAY_PAUSE:
mediaPlay();
break;
case VK_MEDIA_PREV_TRACK:
mediaPrev();
break;
case VK_MEDIA_NEXT_TRACK:
mediaNext();
break;
case VK_F10:
// Exit Case
MessageBox(NULL, TEXT(" Application terminated succefully"),
TEXT(" bluePoint"),
MB_SETFOREGROUND | MB_OK | MB_ICONINFORMATION | MB_TOPMOST);
exit(0);
break;
}
}
return CallNextHookEx(NULL, Code, wParam, lParam);
}
int main() {
MSG msg;
HWND hwnd;
WNDCLASSW wc = {0};
HINSTANCE hInstance;
wc.lpszClassName = L"bluePoint";
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
g_hinst = hInstance;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.hCursor = LoadCursor(0, IDC_ARROW);
RegisterClassW(&wc);
hwnd = CreateWindowW(wc.lpszClassName, L"bluePoint",
WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU, 100, 100,
350, 370, 0, 0, hInstance, 0);
LONG lStyle = GetWindowLong(hwnd, GWL_STYLE);
lStyle &= ~(WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
SetWindowLong(hwnd, GWL_STYLE, lStyle);
SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 350, 370,
SWP_NOMOVE | SWP_FRAMECHANGED);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
HFONT hFont;
static HWND groupBox, comboBox1, comboBox2, comboBox3, label1, label2, label3,
label4, inputBox, okButton, addButton;
const wchar_t *items[] = {
L"None", L"VK_SPACE", L"VK_LEFT", L"VK_RIGHT", L" - Add New key",
};
switch (msg) {
case WM_CREATE:
// Create window controls
hFont =
CreateFont(16, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_SWISS, TEXT("Arial"));
groupBox = CreateWindowW(L"Button", L" Remappings ",
WS_CHILD | WS_VISIBLE | BS_GROUPBOX, 25, 20, 300,
250, hwnd, 0, GetModuleHandle(0), 0);
// SET-1
label1 = CreateWindowW(L"Static", L"Play / Pause :", WS_CHILD | WS_VISIBLE,
50, 70, 130, 60, hwnd, NULL, g_hinst, NULL);
comboBox1 =
CreateWindowW(L"Combobox", NULL,
WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | CBS_DROPDOWNLIST,
160, 70, 140, 300, hwnd, NULL, g_hinst, NULL);
// SET-2
label2 = CreateWindowW(L"Static", L"Next Track :", WS_CHILD | WS_VISIBLE,
50, 130, 130, 60, hwnd, NULL, g_hinst, NULL);
comboBox2 =
CreateWindowW(L"Combobox", NULL,
WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | CBS_DROPDOWNLIST,
160, 130, 140, 300, hwnd, NULL, g_hinst, NULL);
// SET-3
label3 = CreateWindowW(L"Static", L"Prev Track :", WS_CHILD | WS_VISIBLE,
50, 190, 130, 60, hwnd, NULL, g_hinst, NULL);
comboBox3 =
CreateWindowW(L"Combobox", NULL,
WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | CBS_DROPDOWNLIST,
160, 190, 140, 300, hwnd, NULL, g_hinst, NULL);
// Bottom controls
okButton = CreateWindowW(L"Button", L"Apply",
WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 240, 290,
80, 30, hwnd, (HMENU)200, g_hinst, NULL);
addButton =
CreateWindowW(L"Button", L"Add Key", WS_CHILD | BS_DEFPUSHBUTTON, 240,
290, 80, 30, hwnd, (HMENU)101, g_hinst, NULL);
label4 =
CreateWindowW(L"Static", L"©️ ashik saleem", WS_CHILD | WS_VISIBLE,
40, 295, 150, 30, hwnd, NULL, g_hinst, NULL);
inputBox =
CreateWindowW(L"Edit", L" Enter V-Key code..", WS_CHILD | WS_BORDER,
25, 290, 190, 30, hwnd, NULL, g_hinst, NULL);
// Populate elements in comboboxes
for (int i = 0; i < 5; i++) {
SendMessageW(comboBox1, CB_ADDSTRING, 0, (LPARAM)items[i]);
SendMessageW(comboBox2, CB_ADDSTRING, 0, (LPARAM)items[i]);
SendMessageW(comboBox3, CB_ADDSTRING, 0, (LPARAM)items[i]);
}
// Set Combobox default values
SendMessage(comboBox1, CB_SETCURSEL, (WPARAM)1, (LPARAM)0);
SendMessage(comboBox2, CB_SETCURSEL, (WPARAM)2, (LPARAM)0);
SendMessage(comboBox3, CB_SETCURSEL, (WPARAM)2, (LPARAM)0);
SendMessage(label4, WM_SETFONT, WPARAM(hFont),
TRUE); // Change Copyright Font
break;
case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED) {
if (LOWORD(wParam) == 200) {
// 'Apply' Button callback
ch1 = SendMessage(comboBox1, CB_GETCURSEL, 0, 0);
ch2 = SendMessage(comboBox2, CB_GETCURSEL, 0, 0);
ch3 = SendMessage(comboBox3, CB_GETCURSEL, 0, 0);
my_hook = SetWindowsHookEx(WH_KEYBOARD_LL, k_Callback1, NULL, 0);
ShowWindow(hwnd, 0); // Hide window
MessageBox(NULL,
TEXT(" Now listening to keyboard events, Click F10 to Exit"),
TEXT(" bluePoint"),
MB_SETFOREGROUND | MB_OK | MB_ICONINFORMATION | MB_TOPMOST);
MSG msg1;
while (GetMessage(&msg1, NULL, 0, 0) != 0) {
TranslateMessage(&msg1);
DispatchMessageW(&msg1);
}
if (my_hook)
UnhookWindowsHookEx(my_hook);
return TRUE;
} else {
// 'Add Key' Button callback
TCHAR buff[1024];
GetWindowText(inputBox, buff, 1024);
if (ch1 == 4) {
int n = SendMessage(comboBox1, CB_GETCOUNT, 0, 0);
SendMessage(comboBox1, CB_ADDSTRING, 0, (LPARAM)TEXT(buff));
SendMessage(comboBox1, CB_SETCURSEL, (WPARAM)n, (LPARAM)0);
}
if (ch2 == 4) {
int n = SendMessage(comboBox2, CB_GETCOUNT, 0, 0);
SendMessage(comboBox2, CB_ADDSTRING, 0, (LPARAM)TEXT(buff));
SendMessage(comboBox2, CB_SETCURSEL, (WPARAM)n, (LPARAM)0);
}
if (ch3 == 4) {
int n = SendMessage(comboBox3, CB_GETCOUNT, 0, 0);
SendMessage(comboBox3, CB_ADDSTRING, 0, (LPARAM)TEXT(buff));
SendMessage(comboBox3, CB_SETCURSEL, (WPARAM)n, (LPARAM)0);
}
ShowWindow(label4, SW_SHOW);
ShowWindow(okButton, SW_SHOW);
ShowWindow(addButton, SW_HIDE);
ShowWindow(inputBox, SW_HIDE);
}
}
if (HIWORD(wParam) == CBN_SELENDOK) {
ch1 = SendMessage(comboBox1, CB_GETCURSEL, 0, 0);
ch2 = SendMessage(comboBox2, CB_GETCURSEL, 0, 0);
ch3 = SendMessage(comboBox3, CB_GETCURSEL, 0, 0);
if (ch1 == 4 || ch2 == 4 || ch3 == 4) {
ShowWindow(label4, SW_HIDE);
ShowWindow(okButton, SW_HIDE);
ShowWindow(addButton, SW_SHOW);
ShowWindow(inputBox, SW_SHOW);
} else {
ShowWindow(label4, SW_SHOW);
ShowWindow(okButton, SW_SHOW);
ShowWindow(addButton, SW_HIDE);
ShowWindow(inputBox, SW_HIDE);
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProcW(hwnd, msg, wParam, lParam);
}
void mediaPlay() {
// Sends Media_Play_Pause event reamapped key to Active foreground window
INPUT pp;
pp.type = INPUT_KEYBOARD;
pp.ki.wScan = 0;
pp.ki.time = 0;
pp.ki.dwExtraInfo = 0;
pp.ki.wVk = VK_SPACE; // virtual-key code (default: space)
pp.ki.dwFlags = 0;
SendInput(1, &pp, sizeof(INPUT));
// Release key
pp.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &pp, sizeof(INPUT));
}
void mediaNext() {
// Sends Media_Next event reamapped key to Active foreground window
INPUT ns;
ns.type = INPUT_KEYBOARD;
ns.ki.wScan = 0;
ns.ki.time = 0;
ns.ki.dwExtraInfo = 0;
ns.ki.wVk = 0x25; // virtual-key code
ns.ki.dwFlags = 0;
SendInput(1, &ns, sizeof(INPUT));
// Release key
ns.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ns, sizeof(INPUT));
}
void mediaPrev() {
// Sends Media_Prev event reamapped key to Active foreground window
INPUT ps;
ps.type = INPUT_KEYBOARD;
ps.ki.wScan = 0;
ps.ki.time = 0;
ps.ki.dwExtraInfo = 0;
ps.ki.wVk = 0x25; // virtual-key code (default: left)
ps.ki.dwFlags = 0;
SendInput(1, &ps, sizeof(INPUT));
// Release key
ps.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ps, sizeof(INPUT));
}