So I implemented a mousehook as seen here: http://support.microsoft.com/kb/318804.

It works great, but in the event, I have it checking to see if the left mouse was pressed, and if it was, execute a function. This function has some calls to an activex control I'm using. The calls execute fairly slowly, like the computer "freezes" for appox 200ms? while the control loads the file it is supposed to and does the other stuff it is supposed to.

Wellll, the problem is that the mouse event keeps on firing (I think this is the problem) so basically, the slow code keeps on firing over and over and over because the hook thinks the left mouse button is down (when in reality it is not). I'm guessing that what is happening is that the mouse event is not "updating" or refreshing the mouse status properly because the computer is in a semi-frozen state while executing the code, and as a result, it queues the same mouse message over and over, which in turn causes the slow code to be run over and over, which compounds rather quickly.

If, after I click, I leave the mouse still, it will stop after some time, but sometimes it takes longer (seems to matter how many "fake" mouse events fired and are queued).

I've narrowed the problem "slow" code down to one particular function call which loads a file (this is for a VRML 3D model). If I comment out this line, everything works fine, one click is registered as one click and it is all great. As soon as I uncomment this one function call, it goes haywire.

Now, to fix this, I have tried ALOT of things, but the one that I thought would make the most sense is to try to disable the mousehook activity event before the "slow code" function call, and then re-enable afterward. This did not do work, which tells me that apparently, even though there is a single function call, VRML_Refresh(), which in turn executes the "slow code" (among other things), it must *think* that the VRML_Refresh() function has completely finished executing, and moves on and out of the event function, and fires the event again? Maybe I'm just not familiar with events, but I was hoping that since I called VRML_Refresh() in the event, it would wait until this code was executed, THEN exit the event and only once it was exited allow another of the same event to occur, but apparently, it does not wait to finish the current code for the event before firing the same event. This, coupled with any slow code (and here lies the question of how slow is too slow, and how do you know you have too slow code, or maybe it is on the edge of too slow and can be pushed over) seemingly causes a queue and compounding problems in my case.

I somehow need to figure out what is going on! I need the events for the mousehook to either a) recognize what the mouse is REALLY doing, or b) stop events for the mouse while the "slow code" executes.

I'm sorry this is long winded and probably really confusing, but I can't seem to figure enough out to relay the problem any more clearly. I'm thinking I'm doing something majorly wrong here, that hopefully will be obvious to everyone once you read what I've done.

For now, I have a workaround where I have a global bool variable called VRML_Needs_Refresh, which I set to true where I would have called the VRML_Refresh(), and I have a timer that fires every 50ms or so that runs VRML_Refresh() if VRML_Needs_Refresh is true, then it sets VRML_Needs_Refresh to false. This works alright, but it isn't the way I wanted to do it, and more over, I want to know why the hook is doing what it is doing, and how to fix it!