Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- #include <Windows.h>
- #include <stdio.h>
- using namespace std;
- void ExitProgramm();
- HHOOK hMouseHook;
- HHOOK hKeyboardHook;
- LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
- PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT)lParam;
- if (p->vkCode == VK_ESCAPE) {
- printf("<ESC> was pressed\n");
- ExitProgramm();
- }
- return CallNextHookEx(NULL, nCode, wParam, lParam);
- }
- LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam) {
- MOUSEHOOKSTRUCT* pMouseStruct = (MOUSEHOOKSTRUCT*)lParam;
- if (pMouseStruct != NULL) {
- switch (wParam) {
- case WM_LBUTTONDOWN: printf("Left button down\n"); break;
- case WM_LBUTTONUP: printf("Left button up\n"); break;
- case WM_RBUTTONDOWN: printf("Right button down\n"); break;
- case WM_RBUTTONUP: printf("Right button up\n"); break;
- case WM_MOUSEMOVE: printf("Mouse move\n"); break;
- case WM_MOUSEWHEEL: printf("Mouse wheel scroll\n"); break;
- case WM_MOUSEHWHEEL: printf("Mouse hwheel scroll\n"); break;
- }
- }
- return CallNextHookEx(NULL, nCode, wParam, lParam);
- }
- int main() {
- hMouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseProc, NULL, NULL);
- hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, NULL, NULL);
- MSG msg;
- while (!GetMessage(&msg, NULL, NULL, NULL)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- ExitProgramm();
- }
- void ExitProgramm() {
- UnhookWindowsHookEx(hMouseHook);
- UnhookWindowsHookEx(hKeyboardHook);
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment