MouseUp never fires after suppressed MouseDownExt

May 6, 2012 at 5:47 AM

Apparently if I suppress a MouseDownExt event then the next MouseUp event never occurs.
(Unlike how key presses seem to work.)

Is this by design or a bug? Any suggestions for a workaround?

Jul 20, 2012 at 2:21 AM

Not a clue.

I did find out that the "Obsolete" MouseClickExt works as I expected the MouseUp event to.  Used MouseDownExt and MouseClickExt to simulate a Middle Mouse Button under specific conditions when holding down and releasing the Right Mouse button.

Jul 20, 2012 at 5:05 AM

As it turns out two things need to be done in order to not receive mouse up: suppression of mouse down and injection
of another mouse down. If any of those two are skipped then it seem to work fine.

Actually it's a bit more complex than that... the full description and test app can be found here but here is the most
relevant part just to give you an idea of the weirdness:

Mouse to mouse remapping: RMB becomes LMB in notepad.

1. Bring forward a window which is not notepad.
2. Click on notepad to focus it.
3. Hold RMB to select some text.
4. Let go RMB and notice that it's stuck so notepad perceives it like LMB is still held.
5. Still in notepad click RMB to make it unstuck.
6. Hold down RMB again and select text.
7. Let go of the RMB. Lo and behold it's not stuck anymore. Works until...
8. ...LMB anywhere then goto 3. It's broken again.


Jul 24, 2012 at 12:57 PM
Edited Jul 24, 2012 at 1:25 PM

Yeah, that does seem to be the problem when a mouse down and an injection of a different mouse down is used.

My attempt has been trying to emulate a middle mouse button, when a flag is set (MS Touch Mouse).  When the flag is on and the RMB is pressed, I suppress the RMB and inject a MMB_Down with the MouseDownExt event.  Sadly, then the MouseUp event never triggers doing that.  So I use the MouseClickExt event to trigger the MMB_Up on a Flag, which surprisingly does work probably due to Timing with the MouseEventExtArgs.Handled ... maybe thats it?

MouseEventExtArgs.Handled and the Mouse"Event"Ext might be causing the problems with a mouse down, suppressing that specific mouse down, and trying to inject a new mouse command.  Since we do not have a MouseUpExt, any attempt to use MouseUp event gets caught by the MouseEventExtArgs.Handled Flag being true and missed. -- Edit:  Not the case, sadly.  Trying to put in a MouseUpExt doesn't seem to solve the problem, so it might not be the MouseEventExtArgs.Handled flag

Source code diving it is, I think.

Note:  I'm also having trouble of a sticky button, when the Double Click of the injected command is inserted with my attempted work around of a MouseClickExt.  Getting a MouseUpExt, if that does work, might fix that problem I'm having too.

Jul 25, 2012 at 5:09 AM

Thank you for looking into it!

Jul 25, 2012 at 9:44 PM
Edited Jul 25, 2012 at 10:46 PM

I found out why and where the problem occurs, just I have no clue if my fix would have unintended consequences on the original intended uses.

In MouseHookListener.cs, there is a "private void ProcessMouseUp(ref MouseEventExtArgs e)" that is supposed to call up the MouseUp event we want.  What is happening, is it completely ignores the MouseUp if the Handled flag is set to true and only calls it if the Handled Flag is set to false.

So we need to rewrite this command a bit to allow us to get the MouseUp called when MouseDownExt set the Handled flag to true.


        //Altered ProcessMouseUp
private void ProcessMouseUp(ref MouseEventExtArgs e) { InvokeMouseEventHandler(MouseUp, e); if (HasSupressButtonUpFlag(e.Button)) { RemoveSupressButtonUpFlag(e.Button); e.Handled = true; } }

NOW the MouseUp will be called when the MouseDownExt sets the e.Handled flag to true or not, thus allowing for the injection of a new mouse button.  Note, that it still suppresses the original mouse click for me.  I'm not entirely sure why the MouseUp wasn't allowed to always be invoked, so there might be some unintended side-effect or consequence to this until I truly can follow the code.  I've been improvising and testing chaotically rather then sitting down and trying to read through the code to understand it like I should.

(And I can finally ignore the MouseClickExt like intended plus the DoubleClick problems no longer exist!)

Again, note I do note entirely know what the side effects of such a change will be.  I just know, it fixes the problem I have had for suppressing one mouse button under specific conditions while injecting a new mouse button in its place.  No more "sticky" clicks.

Edit:  I've noticed one problem so far.  The suppressed button "MouseUp" signal may still slip through, during rapid usage of the injected button.  This gives you a "Sticky" button the next time you try to use the suppressed button normally.  I'm looking into how to get rid of this, and I've got one idea but I'm researching it more to make sure it doesn't have any errors before mentioning it.  Again, this takes a rather rapid usage of the suppressed&injected mouse button to trigger and I'm still trying to determine where it takes place.

Jul 27, 2012 at 6:10 AM
Edited Jul 27, 2012 at 8:49 AM

Great job Sir! My quick test showed that it's indeed working as expected.

A related problem I still have is remapping a key to a mouse button. I'll double check my high level logic and then I'll see if your mouse fix can be adapted to the keyboard stuff.

Edit: Never mind, everything works fine right until the Mouse.LeftButtonUp() function in the injector lib. o_O

Edit #2: I have to send the up event twice to have any effect in this particular scenario.