Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MOUSEEVENTF_LEFTDOWN in Compiled Program

Status
Not open for further replies.

MaxJo

Programmer
Jan 25, 2023
4
GB
I have written many VB6 programs, and one that I use has to press a button for me automatically , the program having positioned the cursor in the correct position. This works fine in NON compiled format, but when I compile the program, it just does not work.

Its very simple - I use the normal
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0


This has been working for years in compiled format, it even works on some computers, but not my main PC which uses Windows 10. Has anyone experienced thia before or have any idea as to what I can do to correct it ?
 
I don't know why you use such a complicated way to "press a button for me automatically".
You can easily do either:
Code:
Call cmdMyButton_Click()
or
Code:
cmdMyButton.Value = True

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
I think that I have not expressed what I need to do correctly
I am not wanting to press the mouse down on a VB6 programmed button, but one on a web page, so I am not in control of the Button itself at all.

Thanks for your answer anyway.


 
How are you positioning the mouse cursor before synthesizing the left button click?

(I ask because I suspect this is actually where the error lies)
 
Positioning is done as follows

Public Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Sub Set_Cursor_Pos(xpos As Long, ypos As Long)
SetCursorPos xpos, ypos
End Sub


I can call set_cursor_pos from my program, and the cursor moves to where I want it to go. So this shouldn't be a problem. As I have said, it has worked for years, but suddenly on my main PC it will only work in the non compiled program. The variables used are all declared as Long.

Thanks
 
Ah. Drat. I was hoping you might have been using mouse_event to do the positioning as well - mainly because there is on W10 a known difference in the way the IDE handles the required flag declaration compared to the way the compiler treats it, which results in the move failing (and consequently any following mousedown/up not occurring at the right place) But this doesn't effect SetCursorPos

So, whilst I can replicate your issue when using mouse_event, I cannot replicate it when using SetCursorPos. The old story: "Works fine here ...
 
Thanks for taking a look at my problem anyway !!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top