Changeset 47
- Timestamp:
- 06/07/11 11:46:01 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MFCtooling/userlog/userlog.cpp
r39 r47 30 30 static MSG lastmsg; 31 31 32 static bool keysPressed[256]; 33 34 inline bool keyAlreadyPressed(const MSG & msg) { 35 return (msg.message==WM_KEYDOWN || msg.message==WM_SYSKEYDOWN) && keysPressed[msg.wParam]; 36 } 37 38 inline bool keyNotPressed(const MSG & msg) { 39 return (msg.message==WM_KEYUP || msg.message==WM_SYSKEYUP) && !keysPressed[msg.wParam]; 40 } 41 42 32 43 HANDLE mutex; 33 44 … … 39 50 if( mutex == NULL ) { 40 51 MessageBox(0, L"MutexFailure", L"MutexFailure", 0); 52 } 53 for(int i=0; i<256; i++) { 54 keysPressed[i] = false; 41 55 } 42 56 … … 126 140 msg.pt.y = -1; 127 141 msg.time = -1; 128 if( !MessageEquals(lastmsg, msg) ) { 129 lastmsg = msg; 130 HookProc(CALLWNDHOOKID, nCode, &msg); 131 } 142 HookProc(CALLWNDHOOKID, nCode, &msg); 132 143 133 144 return CallNextHookEx(myhookdata[CALLWNDHOOKID].hookhandle, nCode, wParam, lParam); … … 136 147 LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam) { 137 148 PMSG msg = (PMSG) lParam; 138 if( !MessageEquals(*msg, lastmsg)) { 139 lastmsg = *msg; 140 HookProc(GETMSGHOOKID,nCode, msg); 141 } 149 HookProc(GETMSGHOOKID,nCode, msg); 150 142 151 return CallNextHookEx(myhookdata[GETMSGHOOKID].hookhandle, nCode, wParam, lParam); 143 152 } … … 151 160 152 161 DWORD waitResult; 162 // simple heuristic to eliminate duplicate messages 163 if( !( MessageEquals(*msg, lastmsg) || keyAlreadyPressed(*msg) || keyNotPressed(*msg) ) ) { 164 lastmsg = *msg; 165 if( msg->message==WM_KEYDOWN || msg->message==WM_SYSKEYDOWN ) { 166 keysPressed[msg->wParam] = true; 167 } 168 if( msg->message==WM_KEYUP || msg->message==WM_SYSKEYUP ) { 169 keysPressed[msg->wParam] = false; 170 } 171 172 // message filter: 173 // all messages that are defined in this switch statement will be part of the log 174 switch(msg->message) { 175 // messages for monitoring GUI state 176 case WM_CREATE: 177 case WM_DESTROY: 178 case WM_SETTEXT: 179 180 // mouse messages 181 case WM_LBUTTONDOWN: 182 case WM_LBUTTONUP: 183 case WM_LBUTTONDBLCLK: 184 case WM_RBUTTONDOWN: 185 case WM_RBUTTONUP: 186 case WM_RBUTTONDBLCLK: 187 case WM_MBUTTONDOWN: 188 case WM_MBUTTONUP: 189 case WM_MBUTTONDBLCLK: 190 case WM_XBUTTONDOWN: 191 case WM_XBUTTONUP: 192 case WM_XBUTTONDBLCLK: 193 case WM_NCLBUTTONDOWN: 194 case WM_NCLBUTTONUP: 195 case WM_NCLBUTTONDBLCLK: 196 case WM_NCRBUTTONDOWN: 197 case WM_NCRBUTTONUP: 198 case WM_NCRBUTTONDBLCLK: 199 case WM_NCMBUTTONDOWN: 200 case WM_NCMBUTTONUP: 201 case WM_NCMBUTTONDBLCLK: 202 case WM_NCXBUTTONDOWN: 203 case WM_NCXBUTTONUP: 204 case WM_NCXBUTTONDBLCLK: 205 206 // keyboard messages 207 case WM_KEYDOWN: 208 case WM_KEYUP: 209 case WM_SYSKEYDOWN: 210 case WM_SYSKEYUP: 211 212 // internal messages usefull for replay/matching of events 213 case WM_KILLFOCUS: 214 case WM_SETFOCUS: 215 case WM_COMMAND: 216 case WM_HSCROLL: 217 case WM_VSCROLL: 218 case WM_MENUSELECT: 219 case WM_USER: 220 waitResult = WaitForSingleObject(mutex, 1000); 221 if( waitResult==WAIT_OBJECT_0 ) { 222 WriteLogentryWString(msg, nFrom); 223 ReleaseMutex(mutex); 224 } 225 #ifdef __TIMING__ 226 msgCounter++; 227 msgCounterChange = true; 228 #endif // __TIMING__ 229 break; 230 default: 231 break; 232 } 233 } 234 235 /* Source code for an inverse filter 153 236 154 237 // inverse filter: defined messages will be filtered, all else just passes through … … 252 335 // exclude messages 0xC000-0xFFFF 253 336 if( !(msg->message>=0xC000 && msg->message<=0xFFFF) ) { 254 waitResult = WaitForSingleObject(mutex, 1000); 255 if( waitResult==WAIT_OBJECT_0 ) { 256 WriteLogentryWString(msg, nFrom); 257 ReleaseMutex(mutex); 258 } 259 260 #ifdef __TIMING__ 261 msgCounter++; 262 msgCounterChange = true; 263 #endif // __TIMING__ 337 // CODE HERE! 264 338 } 265 339 break; 266 } 340 } */ 341 267 342 #ifdef __TIMING__ 268 343 GetSystemTime( &systemTime );
Note: See TracChangeset
for help on using the changeset viewer.