VB6 Auto click on coordinates
Is there any code that will enable me to click on portions of the form with the use of coordinates? I know most of you find it easier to just use controlname.click but it is not possible for my application. Hope someone can help. Thanks.
martin11ph
Junior Poster in Training
74 posts since Jan 2011
Reputation Points: 7
Solved Threads: 0
martin11ph
Junior Poster in Training
74 posts since Jan 2011
Reputation Points: 7
Solved Threads: 0
Sorry to reopen but I need help pertaining to this code.
Currently, I am using the code given this way and it works fine:
Call MouseMove(775, 120)
Call MouseFullClick(btcLeft)
My problem is that I use this code in a form keydown event. Whenever a key is pressed, the mouse is moved and left clicks another part of the form. I have no idea, given the code, how to store the current x and y position and return it later. This is what I want to do:
Store X
Store Y
Call MouseMove(775, 120)
Call MouseFullClick(btcLeft)
Call MouseMove(X,Y)
Any help would be appreciated. Thanks.
martin11ph
Junior Poster in Training
74 posts since Jan 2011
Reputation Points: 7
Solved Threads: 0
Before the mouse move, get the X and Y coordinates -
Dim X As Integer, Y As Integer
X = MouseX 'Not the correct code, correct with whatever you use to get the coordinates...
'The same with Y...
Now call the move ...
X = X - 1250
Y = Y +1200
Call MouseMove(X,Y)
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
Hi, this is the code I tried. Its kind of weird because I get a ByRef argument type mismatch error. I already made all variables of Long type.
Dim xp, yp As Long
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
xp = CLng(X)
yp = CLng(Y)
End Sub
Private Sub Command1_Click()
Call MouseMove(450, 170)
Call MouseFullClick(btcLeft)
Call MouseMove(xp, yp)
End Sub
martin11ph
Junior Poster in Training
74 posts since Jan 2011
Reputation Points: 7
Solved Threads: 0
Try changing the "Long" to "Single"
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350
Thanks for all your help with my threads. This one is now working but it does not return me to my original location. It sends me very far off.
Dim xp, yp As Single
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
xp = X
yp = Y
End Sub
Private Sub Command1_Click()
Call MouseMove(450, 170)
Call MouseFullClick(btcLeft)
Call MouseMove(CLng(xp), CLng(yp))
End Sub
I also tried making it CLng(xp)-1250 and CLng(yp)+1200 as per your suggestion earlier but it also doesn't bring me back to the original mouse position. I guess I could do trial and error on the + or - value after so that I can get it back to its position.
martin11ph
Junior Poster in Training
74 posts since Jan 2011
Reputation Points: 7
Solved Threads: 0
I think the reason being that the mouse is not over the form anymore, hence the X and Y values is lost. a Lazy way around, but quickest solution, is to add two text boxes, visible values as false. Now add the x and y positions to these text boxes, now call it from the command click event.
AndreRet
Senior Poster
3,922 posts since Jan 2008
Reputation Points: 334
Solved Threads: 350