public virtual IntPtr Callback(int code, IntPtr wparam, IntPtr lparam) { NativeMethods.EVENTMSG eventmsg = Marshal.PtrToStructure <NativeMethods.EVENTMSG>(lparam); if (UnsafeNativeMethods.GetAsyncKeyState((int)Keys.Pause) != 0) { SendKeys.stopHook = true; } // switch (code) { case NativeMethods.HC_SKIP: if (!gotNextEvent) { break; } if (SendKeys.events != null && SendKeys.events.Count > 0) { SendKeys.events.Dequeue(); } SendKeys.stopHook = SendKeys.events == null || SendKeys.events.Count == 0; break; case NativeMethods.HC_GETNEXT: gotNextEvent = true; #if DEBUG Debug.Assert(SendKeys.events != null && SendKeys.events.Count > 0 && !SendKeys.stopHook, "HC_GETNEXT when queue is empty!"); #endif SKEvent evt = (SKEvent)SendKeys.events.Peek(); eventmsg.message = evt.wm; eventmsg.paramL = evt.paramL; eventmsg.paramH = evt.paramH; eventmsg.hwnd = evt.hwnd; eventmsg.time = SafeNativeMethods.GetTickCount(); Marshal.StructureToPtr(eventmsg, lparam, true); break; default: if (code < 0) { UnsafeNativeMethods.CallNextHookEx(new HandleRef(null, SendKeys.hhook), code, wparam, lparam); } break; } if (SendKeys.stopHook) { SendKeys.UninstallJournalingHook(); gotNextEvent = false; } return(IntPtr.Zero); }
public virtual IntPtr Callback(int code, IntPtr wparam, IntPtr lparam) { System.Windows.Forms.NativeMethods.EVENTMSG structure = (System.Windows.Forms.NativeMethods.EVENTMSG)UnsafeNativeMethods.PtrToStructure(lparam, typeof(System.Windows.Forms.NativeMethods.EVENTMSG)); if (UnsafeNativeMethods.GetAsyncKeyState(0x13) != 0) { SendKeys.stopHook = true; } switch (code) { case 1: { this.gotNextEvent = true; SendKeys.SKEvent event2 = (SendKeys.SKEvent)SendKeys.events.Peek(); structure.message = event2.wm; structure.paramL = event2.paramL; structure.paramH = event2.paramH; structure.hwnd = event2.hwnd; structure.time = SafeNativeMethods.GetTickCount(); Marshal.StructureToPtr(structure, lparam, true); break; } case 2: if (this.gotNextEvent) { if ((SendKeys.events != null) && (SendKeys.events.Count > 0)) { SendKeys.events.Dequeue(); } SendKeys.stopHook = (SendKeys.events == null) || (SendKeys.events.Count == 0); } break; default: if (code < 0) { UnsafeNativeMethods.CallNextHookEx(new HandleRef(null, SendKeys.hhook), code, wparam, lparam); } break; } if (SendKeys.stopHook) { SendKeys.UninstallJournalingHook(); this.gotNextEvent = false; } return(IntPtr.Zero); }