Advertisement
Guest User

Untitled

a guest
Aug 25th, 2010
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "Input-Hook.h"
  3.  
  4.  
  5.  
  6. #ifdef _MANAGED
  7. #pragma managed(push, off)
  8. #endif
  9.  
  10. HINSTANCE hDLL;
  11.  
  12. BOOL APIENTRY DllMain(HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved) {
  13.     if(ul_reason_for_call == DLL_PROCESS_ATTACH)  // When initializing....
  14.     {
  15.         hDLL = hModule;
  16.         // We don't need thread notifications for what we're doing.  Thus, get
  17.         // rid of them, thereby eliminating some of the overhead of this DLL
  18.         DisableThreadLibraryCalls( hModule );
  19.     }
  20.  
  21.     return TRUE;
  22. }
  23.  
  24. // This segment must be defined as SHARED in the .DEF
  25. #pragma data_seg (".HookSection")      
  26. // Shared instance for all processes.
  27. HHOOK hookKeyboard = NULL;
  28. #pragma data_seg ()
  29.  
  30. INPUTHOOK_API LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
  31.     Beep(0x300, 80); return 0;
  32.     KBDLLHOOKSTRUCT* keyboard = (KBDLLHOOKSTRUCT*)lParam;
  33.     bool keydown = wParam == 0x100 ? true : false;
  34.    
  35.     if (keyboard->vkCode == 0x57) { // W
  36.         if (keydown) {
  37.             Beep(0x300, 80);
  38.         } else {
  39.             Beep(0x200, 80);
  40.         }
  41.     }
  42.  
  43.     return 0;//CallNextHookEx(hookKeyboard, nCode, wParam, lParam);
  44. }
  45.  
  46. INPUTHOOK_API void InstallInputHook()
  47. {
  48.  
  49.     hookKeyboard = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, NULL, 0);
  50.     OutputDebugString( "INPUTHOOK hook installed.\n" );
  51. }
  52.  
  53. INPUTHOOK_API void RemoveInputHook()
  54. {
  55.     UnhookWindowsHookEx(hookKeyboard);
  56.     OutputDebugString( "INPUTHOOK hook removed.\n" );
  57. }
  58.  
  59.  
  60. #ifdef _MANAGED
  61. #pragma managed(pop)
  62. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement