Jump to content
Sign in to follow this  
Gizmo42

2 little Question about functions

Recommended Posts

Gizmo42

Howdy :)

I hate 2 little questions about the AutoIt functions:

1. There are differences between the "ControlClick" to the "Send" functions? (Enter,TAB,Space).. Which is "better" to use?

2. There's any way to use "MouseClick" function, which will work on any computer ? I mean; If I create a script on my computer, then I have a specific location of a window (the X and the Y coordinates ). so if I use "Mouse Click" on a window on my computer, and someone else have a different computer or screen size, it won't work.

There's a way to find a common X and Y coordinates or use a different way to locate mouse click?

I'll be glad to answers,

cheers guys ;)

Edited by Gizmo42

Share this post


Link to post
Share on other sites
kaotkbliss

Controlclick and controlsend will find the control wherever it is on the screen and interact with it, even if you are doing something else manually where straight send will use the current active control.


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites
monoscout999

My poor experience with mouseclick() tells me that i have to do some maths...

For ex.

In My PC the x spot where i want to click is in the 400 pixel.

In another PC is not in the same position because the resolution change.

So i do some maths. First, i think.. The porcentage of the desktopwidth that tells me where is the spot

If desktopwidth is the 100% then 400 will be the xx%

$xPercent = 400 * 100 / @DesktopWidth

so i grab that number and start using that number instead of 400 in the following way

$x = xPercent * @DesktopWidth / 100

I hope you understand my way to do it.

You can also do it with the windows width, instead the Desktop Width.

EDITED: Added some info

Edited by monoscout999

Share this post


Link to post
Share on other sites
Gizmo42

Controlclick and controlsend will find the control wherever it is on the screen and interact with it, even if you are doing something else manually where straight send will use the current active control.

Actually I was talking about "ControlClick" and "Send", not controlsend.

So you just saying there is not differences between the ControlClick & Send functions? I'm asking because I saw the description of the ControlClick:

"Sends a mouse click command to a given control." ~> And I didn't saw any mouse click, only same actions like the "Send" function ;)

My poor experience with mouseclick() tells me that i have to do some maths...

For ex.

In My PC the x spot where i want to click is in the 400 pixel.

In another PC is not in the same position because the resolution change.

So i do some maths. First, i think.. The porcentage of the desktopwidth that tells me where is the spot

If desktopwidth is the 100% then 400 will be the xx%

$xPercent = 400 * 100 / @DesktopWidth

so i grab that number and start using that number instead of 400 in the following way

$x = xPercent * @DesktopWidth / 100

I hope you understand my way to do it.

You can also do it with the windows width, instead the Desktop Width.

EDITED: Added some info

Actually I don't understood :)

You mean that I can use MouseClick() function on every computer and click on the same button for exmaple I wanted?

I mean, if in my computer I wanted to click on a button called "Prize", which found in 432, 659

It can click on the "Prize" button in other computer, which found in 957, 854 ? This is my question :]

If yes, how?

I didn't understood your math, sorry :}

EDITED: Smiley ^^

Edited by Gizmo42

Share this post


Link to post
Share on other sites
monoscout999

mmmmh....

You have the width of 1000... so the pixel 500 is founded in the middle.

1000 is the 100% and 500 is the 50%

instead of using the pixel number. use the percentage.

I will explain it better in a while

Share this post


Link to post
Share on other sites
sleepydvdr

If you want to click in the location within a program that can be located in different locations from one computer to the next, you should use ControlClick. Use the AutoIt Info tool to find the relative coordinates within the program's window. A better option may be using the AutoIt Info tool to find the class and instance of the button and using that information to use ControlClick.

That's about all I can do to help you because a button named "Prize" sounds like something we really shouldn't be discussing.


#include <ByteMe.au3>

Share this post


Link to post
Share on other sites
Gizmo42

If you want to click in the location within a program that can be located in different locations from one computer to the next, you should use ControlClick. Use the AutoIt Info tool to find the relative coordinates within the program's window. A better option may be using the AutoIt Info tool to find the class and instance of the button and using that information to use ControlClick.

That's about all I can do to help you because a button named "Prize" sounds like something we really shouldn't be discussing.

Can you give me an example to a ControlClick()? I don't understand how to use the class and the instance :S

And I want to use MouseClick(), not ControlClick ..

There is no way to use MouseClick() with a button ID or something INSTEAD of coordinates?

"Prize" it's just a name. I can called it "dog", "cat" or even "mutation". That's not the point..

BTW,

If I use ControlClick() to a button OR use Send({ENTER}) to the same button, there is a difference?

Edited by Gizmo42

Share this post


Link to post
Share on other sites
sleepydvdr

Can you give me an example to a ControlClick()? I don't understand how to use the class and the instance :S

And I want to use MouseClick(), not ControlClick ..

There is no way to use MouseClick() with a button ID or something INSTEAD of coordinates?

"Prize" it's just a name. I can called it "dog", "cat" or even "mutation". That's not the point..

BTW,

If I use ControlClick() to a button OR use Send({ENTER}) to the same button, there is a difference?

OK, I will give you an example using the calculator:

ShellExecute("calc")
WinWaitActive("Calculator")
ControlClick("Calculator", "", "[CLASS:Button; INSTANCE:44]", "Left", 1)
Sleep(500)
ControlClick("Calculator", "", "[CLASS:Button; INSTANCE:49]", "Left", 1)
Sleep(500)
ControlClick("Calculator", "", "[CLASS:Button; INSTANCE:54]", "Left", 1)
Sleep(500)
ControlClick("Calculator", "", "[CLASS:Button; INSTANCE:43]", "Left", 1)
Sleep(500)
ControlClick("Calculator", "", "[CLASS:Button; INSTANCE:48]", "Left", 1)

And to answer your other question: sending enter is not the same as control click. However, sometimes they can produce the same results. ControlClick is more of a precise way of doing it. If you send a key and the window is not the active window, it will not do what you want.


#include <ByteMe.au3>

Share this post


Link to post
Share on other sites
Gizmo42

OK, I will give you an example using the calculator:

ShellExecute("calc")
WinWaitActive("Calculator")
ControlClick("Calculator", "", "[CLASS:Button; INSTANCE:44]", "Left", 1)
Sleep(500)
ControlClick("Calculator", "", "[CLASS:Button; INSTANCE:49]", "Left", 1)
Sleep(500)
ControlClick("Calculator", "", "[CLASS:Button; INSTANCE:54]", "Left", 1)
Sleep(500)
ControlClick("Calculator", "", "[CLASS:Button; INSTANCE:43]", "Left", 1)
Sleep(500)
ControlClick("Calculator", "", "[CLASS:Button; INSTANCE:48]", "Left", 1)

And to answer your other question: sending enter is not the same as control click. However, sometimes they can produce the same results. ControlClick is more of a precise way of doing it. If you send a key and the window is not the active window, it will not do what you want.

Ohhhhhh thank you thank you !! Now I understood it!

But one more little thing:

Again, there is no option to use an ID or something instead of X,Y coordinates in a MouseClick()?

I'm asking because I want to perform a mouse click, to see the click of the mouse ..

And the disadvantage of the MouseClick() is the changing coordinates :S

2 More questions and I done here :)

1. The ControlClick(), works on any computer? (not like MouseClick that need coordinates). I mean - there's a common Instance for a button for exmaple in any computer?

Because in the script you gave me, above, I have a different instances in my calculator, so it won't work ..

2. How can I close notepad With ControlClick() only? because the "Exit" in the menu there's no ID/Instance/class ..

Edited by Gizmo42

Share this post


Link to post
Share on other sites
kaotkbliss

Actually I was talking about "ControlClick" and "Send", not controlsend.

So you just saying there is not differences between the ControlClick & Send functions? I'm asking because I saw the description of the ControlClick:

Read what I wrote more carefully.

Particularly "where straight send will use the current active control"


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites
sleepydvdr

I do not believe you can use an ID for mouseclick. The help file does not say anything about that option.

1. You must have a different OS than me (I have XP). Therefore, our calculators are different. Similarly, if you have different versions of software from one computer to the next, the IDs may be different. But if two computers are running the same software, the IDs would be the same.

2. In the case of closing a program, you may be able to use this:

$coord = WinGetPos ("Untitled - Notepad")
MouseClick("left",  $coord[0] + $coord[2] - 15, $coord[1] + 15, 1)

That code gets the coordinates of Notepad and I am getting it to perform a single click 15 pixels left & down from the upper right corner (where my close button is). Then it may prompt you to save and you can run an If/Then check to see if it did.


#include <ByteMe.au3>

Share this post


Link to post
Share on other sites
Gizmo42

Read what I wrote more carefully.

Particularly "where straight send will use the current active control"

Ok, I understood it already, thanks :)

But I have the 3 last quesions in comment 9 :]

Edited by Gizmo42

Share this post


Link to post
Share on other sites
monoscout999

Try this, i use the CLASS name because i have Spanish OS for me "Calculator" is "Calculadora", Classnames are the same in any languaje.

Look the coor mode that i use, is the active client coor mode.

And i have a different instance numer from the "1" button than @sleepydvdr, i have Win7 64x, maybe is because that.. look with the AutoIt Window info wich INSTANCE do you have.

Opt("MouseCoordMode",2)
#include <array.au3>
If not winexists("[Class:CalcFrame]") then ShellExecute("calc")
winwait("[Class:CalcFrame]")
$hndl = WinActivate("[Class:CalcFrame]")
$CtrlHndl = ControlGetHandle($hndl,"","[CLASS:Button; INSTANCE:5]")
controlclick($hndl,"","[CLASS:Button; INSTANCE:5]")
sleep(500)
$pos = Controlgetpos($hndl,"",$CtrlHndl)
mousemove($pos[0],$pos[1])
sleep(500)
mousemove($pos[0]+$pos[2],$pos[1]+$pos[3])
Edited by monoscout999

Share this post


Link to post
Share on other sites
sleepydvdr

Ok, I understood it already, thanks :)

But I have the 3 last quesions in comment 9 :]

I think you missed my reply.


#include <ByteMe.au3>

Share this post


Link to post
Share on other sites
Gizmo42

I do not believe you can use an ID for mouseclick. The help file does not say anything about that option.

1. You must have a different OS than me (I have XP). Therefore, our calculators are different. Similarly, if you have different versions of software from one computer to the next, the IDs may be different. But if two computers are running the same software, the IDs would be the same.

2. In the case of closing a program, you may be able to use this:

$coord = WinGetPos ("Untitled - Notepad")
MouseClick("left",  $coord[0] + $coord[2] - 15, $coord[1] + 15, 1)

That code gets the coordinates of Notepad and I am getting it to perform a single click 15 pixels left & down from the upper right corner (where my close button is). Then it may prompt you to save and you can run an If/Then check to see if it did.

1. Ok, thanks (:

2. If you can perform this mouse click to exit a program for exmaple, why cant you use the MouseClick to other cases? for example button clicks in calculator or stuff?

And how do you found the coords?

and what are those "" $coords[0][2][1] +15 "" anyway? I don't understood that code :)

Try this, i use the CLASS name because i have Spanish OS for me "Calculator" is "Calculadora", Classnames are the same in any languaje.

Look the coor mode that i use, is the active client coor mode.

And i have a different instance numer from the "1" button than @sleepydvdr, i have Win7 64x, maybe is because that.. look with the AutoIt Window info wich INSTANCE do you have.

Opt("MouseCoordMode",2)
#include <array.au3>
If not winexists("[Class:CalcFrame]") then ShellExecute("calc")
winwait("[Class:CalcFrame]")
$hndl = WinActivate("[Class:CalcFrame]")
$CtrlHndl = ControlGetHandle($hndl,"","[CLASS:Button; INSTANCE:5]")
controlclick($hndl,"","[CLASS:Button; INSTANCE:5]")
sleep(500)
$pos = Controlgetpos($hndl,"",$CtrlHndl)
mousemove($pos[0],$pos[1])
sleep(500)
mousemove($pos[0]+$pos[2],$pos[1]+$pos[3])

Ok, thanks, I'll check out this code :] Edited by Gizmo42

Share this post


Link to post
Share on other sites
sleepydvdr

The function WinGetPos gives you x, y, width and height of the window. You can use that to click at a specific coordinate within that window. So, using WinGetPos, you essentially can do what you want with MouseClick.


#include <ByteMe.au3>

Share this post


Link to post
Share on other sites
monoscout999

controlgetpos() give you the coord of the control inside the client area.

Share this post


Link to post
Share on other sites
Gizmo42

The function WinGetPos gives you x, y, width and height of the window. You can use that to click at a specific coordinate within that window. So, using WinGetPos, you essentially can do what you want with MouseClick.

Ohh cool, that's what I wanted! :)

But I don't get it .. how the WinGetPos gives me the x,y ? how you found that to exit notepad for example, it was: "$coord[0] + $coord[2] - 15, $coord[1] + 15" ..

Please explain me how to use this WinGetPos to get a x,y position of a window, that will helped me!! ;)

controlgetpos() give you the coord of the control inside the client area.

ditto ^^

Can you explain me please how to use that function? I don't get it :S

Edited by Gizmo42

Share this post


Link to post
Share on other sites
monoscout999

i already post you an example.

Share this post


Link to post
Share on other sites
Gizmo42

But I didn't understood how to find the coordinates of a button for example :S

With WinGetPos or controlgetpos()..

Edited by Gizmo42

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×