Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "Input-Hook.h"
- #ifdef _MANAGED
- #pragma managed(push, off)
- #endif
- HINSTANCE hDLL;
- BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
- if(ul_reason_for_call == DLL_PROCESS_ATTACH) // When initializing....
- {
- hDLL = hModule;
- // We don't need thread notifications for what we're doing. Thus, get
- // rid of them, thereby eliminating some of the overhead of this DLL
- DisableThreadLibraryCalls( hModule );
- }
- return TRUE;
- }
- // This segment must be defined as SHARED in the .DEF
- #pragma data_seg (".HookSection")
- // Shared instance for all processes.
- HHOOK hookKeyboard = NULL;
- #pragma data_seg ()
- INPUTHOOK_API LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
- Beep(0x300, 80); return 0;
- KBDLLHOOKSTRUCT* keyboard = (KBDLLHOOKSTRUCT*)lParam;
- bool keydown = wParam == 0x100 ? true : false;
- if (keyboard->vkCode == 0x57) { // W
- if (keydown) {
- Beep(0x300, 80);
- } else {
- Beep(0x200, 80);
- }
- }
- return 0;//CallNextHookEx(hookKeyboard, nCode, wParam, lParam);
- }
- INPUTHOOK_API void InstallInputHook()
- {
- hookKeyboard = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, NULL, 0);
- OutputDebugString( "INPUTHOOK hook installed.\n" );
- }
- INPUTHOOK_API void RemoveInputHook()
- {
- UnhookWindowsHookEx(hookKeyboard);
- OutputDebugString( "INPUTHOOK hook removed.\n" );
- }
- #ifdef _MANAGED
- #pragma managed(pop)
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement