Reputation: 31
TL;DR:
I need to use both sendmessage
and sendinput
in order to get into an old function/event in a program that I can't re-build. While in there, I can't release the virtual mouse click using any of the methods I used to get in there in the first place - they're ignored.
Any other way to trigger the mousedown event - one where I could also release the mouse click might work.
I am writing a program that has to interact with a black-boxed old piece of software written in VB6 long long ago. My program has to be able to send mouse clicks, specifically mousedown and mouseup events to the old program.
Here's the tricky part... The mousedown event in the old program uses:
While GetAsyncKeyState(1)
Wend
to wait for the user to release the mouse.
Currently, in order to get the event to trigger, I need to use:
SendMessage(control_handle, WM_LBUTTONDOWN, 0, 0);
Input.type = INPUT_MOUSE;
Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
SendInput(1,&Input,sizeof(INPUT));
This does trigger the event (using just sendmessage
does NOT trigger a necessary branch inside the event because that branch is entered with a GetAsyncKeyState(1)
test as well), but issuing any combination of the following does NOT release the mouse click:
SendMessage(control_handle, WM_LBUTTONUP, 0, 0)
Input.type = INPUT_MOUSE;
Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput(1,&Input,sizeof(INPUT));
The code just keeps repeating in the while/wend part, it never gets out. The release code is being sent, but GetAsyncKeyState(1)
isn't recognizing it as a mouse release. SUPER weird that GetAsyncKeyState(1)
recognizes the function as a mouse down event, but GetAsyncKeyState(1)
won't recognize as a mouse up.
What I've tested:
Clicking the real mouse elsewhere on the screen does release the function.
Removing the sendmessage call, and using just the sendinput function (and manually positioning the mouse over the object that needs clicking) DOES work to release the loop.
I can't rely on the user not messing with the mouse while this is doing its thing, so I'm hesitant to have the code virtually move the mouse over the button to be clicked.
I've tried the deprecated mouse_event function as well, same exact behavior.
Timing is critical. There can't be substantial delays between the trigger is issued and when it happens. Think keyboard-response speed.
I wrote a very simple VB6 program to simulate the while/GetAsyncKeyState(1)/wend
loop to test this out on, and the behavior is the same - so I can be confident there isn't something weird in the old program that is causing this to happen.
Thank you very much for reading and helping!
Upvotes: 2
Views: 394
Reputation: 31
In case this ever comes up for anyone else ever.... Using postmessage instead of sendmessage allows the program to continue on. Makes sense, really..
Upvotes: 1