-
Notifications
You must be signed in to change notification settings - Fork 0
/
clswitch.c
56 lines (52 loc) · 1.65 KB
/
clswitch.c
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
#include <windows.h>
HHOOK hook;
LRESULT CALLBACK keyboardHook(int nCode, WPARAM wParam, LPARAM lParam) {
KBDLLHOOKSTRUCT *p = (KBDLLHOOKSTRUCT *)lParam;
WORD keyCode = (WORD)p->vkCode;
if ((keyCode == VK_CAPITAL) && !(p->flags&LLKHF_INJECTED) && nCode >= 0) {
if (GetKeyState(VK_CONTROL) & 0x8000) goto call_next;
if (wParam == WM_KEYUP)
PostMessage(GetForegroundWindow(), WM_INPUTLANGCHANGEREQUEST, 2, 0);
return 1;
};
call_next:
return CallNextHookEx(hook, nCode, wParam, lParam);
}
LRESULT CALLBACK WndProc(HWND ihwnd, UINT umsg, WPARAM wParam, LPARAM lParam) {
if ((umsg == WM_CLOSE) || (umsg == WM_DESTROY) || (umsg == WM_ENDSESSION)) {
PostQuitMessage(0);
return 0;
}
else return DefWindowProc(ihwnd, umsg, wParam, lParam);
}
extern "C" void startup(void) {
HINSTANCE hInstance=GetModuleHandle(NULL);
SetProcessWorkingSetSize(GetCurrentProcess(), (SIZE_T) -1, (SIZE_T) -1);
HWND hwnd;
WNDCLASS wc = {};
LPCSTR cl_name = (LPCSTR)"capsfinder";
SetLastError(0);
HANDLE iMutex = CreateMutex(NULL, TRUE, cl_name);
if (iMutex) {
if (GetLastError() == ERROR_ALREADY_EXISTS) goto return_point_0;
}
else goto return_point_0;
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.lpszClassName = cl_name;
if (!RegisterClass(&wc)) goto return_point_1;
hwnd = CreateWindow(cl_name, NULL, 0, 0, 0, 0, 0, 0, 0, hInstance, 0);
if (!hwnd) goto return_point_2;
hook = SetWindowsHookEx(WH_KEYBOARD_LL, keyboardHook, NULL, 0);
if (hook) {
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) > 0)
DispatchMessage(&msg);
};
return_point_2:
UnregisterClass(cl_name, hInstance);
return_point_1:
CloseHandle(iMutex);
return_point_0:
ExitProcess(0);
}