AppHooker

Dec 12, 2014 at 12:55 PM
I'm listening to mouse events by using GlobalHook everything is ok but now i realized i really need only to listen for application events so i used AppHooker. AppHooker however do not fire any event. I'm using it like this inside a form:
  _mouseListener = new MouseHookListener( new AppHooker() );
  _mouseListener.MouseClick += _mouseListener_MouseClick;
  _mouseListener.MouseDown += _mouseListener_MouseDown;
Jan 13, 2015 at 12:28 PM
Edited Jan 13, 2015 at 12:42 PM
I noticed the same thing. There seems to be a disconnect in the mouse click handling when you use the AppHooker. The ProcessMouseClick method contains this conditional block for raising the MouseClick event:
if ((m_DownButtonsWaitingForMouseUp & e.Button) != MouseButtons.None)
{
    m_PreviousClicked = e.Button;
    m_PreviousClickedPosition = e.Point;
    m_DownButtonsWaitingForMouseUp = MouseButtons.None;
    InvokeMouseEventHandler(MouseClick, e);
    InvokeMouseEventHandlerExt(MouseClickExt, e);
}
However, with the AppHooker, there seems to be no way for m_DownButtonsWaitingForMouseUp to ever have any value other than MouseButtons.None because ProcessMouseDown has this:
if (IsGlobal)
{
    ProcessPossibleDoubleClick(ref e);
}
else
{
    // These are only used for global. No need for them in AppHooks
    m_DownButtonsWaitingForMouseUp = MouseButtons.None;
    m_PreviousClicked = MouseButtons.None;
    m_PreviousClickedTime = 0;
} 
And the AppHooker always returns false for IsGlobal. Cosequently, the MouseClick event never gets raised.

In the Issues list, the following fix is suggested for ProcessMouseClick:
if ((m_DownButtonsWaitingForMouseUp & e.Button) != MouseButtons.None ||
    (!IsGlobal && e.Button != MouseButtons.None))