1 // W32LowLevelMonitor.cc --- ActivityMonitor for W32 2 // 3 // Copyright (C) 2007, 2010, 2012 Ray Satiro <raysatiro@yahoo.com> 4 // All rights reserved. 5 // 6 // This program is free software; you can redistribute it and/or modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation; either version 3, or (at your option) 9 // any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 17 #ifndef W32LOWLEVELMONITOR_HH 18 #define W32LOWLEVELMONITOR_HH 19 20 #include "InputMonitor.hh" 21 22 class W32LowLevelMonitor : 23 public InputMonitor 24 { 25 public: 26 W32LowLevelMonitor(); 27 virtual ~W32LowLevelMonitor(); 28 bool init(); 29 void terminate(); 30 static W32LowLevelMonitor *singleton; 31 32 protected: 33 static DWORD WINAPI thread_Dispatch( LPVOID ); 34 static DWORD WINAPI thread_Callback( LPVOID ); 35 36 private: 37 38 struct thread_struct 39 { 40 volatile bool active; 41 DWORD id; 42 HANDLE handle; 43 const char *name; thread_structW32LowLevelMonitor::thread_struct44 thread_struct() 45 { 46 active = false; 47 id = 0; 48 handle = NULL; 49 name = NULL; 50 } 51 }; 52 static thread_struct *dispatch, *callback; 53 54 bool wait_for_thread_queue( thread_struct * ); 55 void terminate_thread( thread_struct * ); 56 void wait_for_thread_to_exit( thread_struct * ); 57 void unhook(); 58 59 DWORD dispatch_thread(); 60 DWORD time_critical_callback_thread(); 61 62 static LRESULT CALLBACK k_hook_callback( int, WPARAM, LPARAM ); 63 static LRESULT CALLBACK m_hook_callback( int, WPARAM, LPARAM ); 64 65 static volatile HHOOK k_hook; 66 static volatile HHOOK m_hook; 67 68 static HMODULE process_handle; 69 }; 70 71 #ifndef WM_XBUTTONDOWN 72 #define WM_XBUTTONDOWN 523 73 #endif 74 75 #ifndef WM_XBUTTONUP 76 #define WM_XBUTTONUP 524 77 #endif 78 79 #ifndef WM_XBUTTONDBLCLK 80 #define WM_XBUTTONDBLCLK 525 81 #endif 82 83 #ifndef WM_MOUSEHWHEEL 84 #define WM_MOUSEHWHEEL 526 85 #endif 86 87 #define LLKHF_INJECTED 0x00000010 88 #define LLMHF_INJECTED 0x00000001 89 90 typedef struct { 91 DWORD vkCode; 92 DWORD scanCode; 93 DWORD flags; 94 DWORD time; 95 ULONG_PTR dwExtraInfo; 96 } _KBDLLHOOKSTRUCT; 97 98 typedef struct { 99 POINT pt; 100 DWORD mouseData; 101 DWORD flags; 102 DWORD time; 103 ULONG_PTR dwExtraInfo; 104 } _MSLLHOOKSTRUCT; 105 106 #endif // W32LOWLEVELMONITOR_HH 107