示例#1
0
        // ************************************************************************

        // ************************************************************************
        // Default filter function
        protected int CoreHookProc(int code, IntPtr wParam, IntPtr lParam)
        {
            if (code < 0)
            {
                return(CallNextHookEx(m_hhook, code, wParam, lParam));
            }

            // Let clients determine what to do
            HookEventArgs e = new HookEventArgs();

            e.HookCode = code;
            e.wParam   = wParam;
            e.lParam   = lParam;
            OnHookInvoked(e);

            // Yield to the next hook in the chain
            return(CallNextHookEx(m_hhook, code, wParam, lParam));
        }
 /// <summary>
 /// LocalWindowsHook.HookInvoked event callback, called by LocalWindowsHook
 /// when a message is received.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 void LocalWindowsHook_HookInvoked(object sender, HookEventArgs e)
 {
   if (e.HookCode >= 0 && new IntPtr(WindowMessage.PM_REMOVE) == e.wParam)
   {
     // Copy the message to a local int variable
     var msg = (uint)Marshal.ReadInt32(e.lParam, Marshal.OffsetOf(typeof(WindowsInterop.MSG), "Msg").ToInt32());
     // Don't translate non-input events.
     if (msg >= WindowMessage.WM_KEYFIRST && msg <= WindowMessage.WM_KEYLAST)
     {
       if (WindowsInterop.IsDialogMessage(m_Control.Handle, e.lParam) != 0)
       {
         // The value returned from this hook is ignored, 
         // and it cannot be used to tell Windows the message has been handled.
         // To avoid further processing, convert the message to WM_NULL 
         // before returning.
         var type = typeof (WindowsInterop.MSG);
         Marshal.WriteInt32(e.lParam, Marshal.OffsetOf(type, "Msg").ToInt32(), WindowMessage.WM_NULL);
         Marshal.WriteInt32(e.lParam,Marshal.OffsetOf(type, "wParam").ToInt32(), 0);
         Marshal.WriteInt32(e.lParam, Marshal.OffsetOf(type, "lParam").ToInt32(), 0);
       }
     }
   }
 }
示例#3
0
    // ************************************************************************

    // ************************************************************************
    // Default filter function
    protected int CoreHookProc(int code, IntPtr wParam, IntPtr lParam)
    {
      if (code < 0)
        return CallNextHookEx(m_hhook, code, wParam, lParam);

      // Let clients determine what to do
      HookEventArgs e = new HookEventArgs();
      e.HookCode = code;
      e.wParam = wParam;
      e.lParam = lParam;
      OnHookInvoked(e);

      // Yield to the next hook in the chain
      return CallNextHookEx(m_hhook, code, wParam, lParam);
    }
示例#4
0
 protected void OnHookInvoked(HookEventArgs e)
 {
   if (HookInvoked != null)
     HookInvoked(this, e);
 }