Jump to content

Screen to Client coordinates conversion


Recommended Posts

I can't convert X and Y coordinates to client from screen.

Here's the code:

#include <WinAPI.au3>
$x_koef = 65535/@DesktopWidth
$y_koef = 65535/@DesktopHeight
$User32 = DllOpen("User32.dll")
$hWnd = WinGetHandle('notepad.exe')

Click(153, 465)

Func Click($x, $y)
$x *= $x_koef
$y *= $y_koef
Local $tpoint = DllStructCreate("int X;int Y")
DllStructSetData($tpoint, "X", $x)
DllStructSetData($tpoint, "Y", $y)
_WinAPI_ScreenToClient($hWnd,$tpoint)
$x = DllStructGetData($tpoint, "X")
$y = DllStructGetData($tpoint, "Y")
;MsgBox(0,'Title',$x&@CRLF&$y)
DllCall($User32, "none", "mouse_event", "int", 32769, "int", $x, "int", $y, "int", 0, "int", 0) ; 32769 0x8001 BitOR($MOUSEEVENTF_ABSOLUTE, $MOUSEEVENTF_MOVE)
DllCall($User32, "none", "mouse_event", "int", 32770, "int", $x, "int", $y, "int", 0, "int", 0) ; 32770 0x8002 BitOR($MOUSEEVENTF_ABSOLUTE, $MOUSEEVENTF_LEFTDOWN)
DllCall($User32, "none", "mouse_event", "int", 32772, "int", $x, "int", $y, "int", 0, "int", 0) ; 32772 0x8004 BitOR($MOUSEEVENTF_ABSOLUTE, $MOUSEEVENTF_LEFTUP)
EndFunc

I fixed it with that:

$winpos = WinGetPos($hWnd)
$x += $winpos[0] + 5
$y += $winpos[1] + 24

Aren't there any other methods?

Edited by VixinG

[indent=3][/indent]

Link to comment
Share on other sites

If you are talking about clicking the client area of notepad window then you might do this.

Opt("MouseCoordMode", 2) ;1=absolute, 0=relative, 2=client

$hWnd = WinGetHandle('notepad.exe')

WinActivate($hWnd)
WinWaitActive($hWnd)

MouseClick("Primary",153, 465)
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

If you are talking about clicking the client area of notepad window then you might do this.

Opt("MouseCoordMode", 2) ;1=absolute, 0=relative, 2=client

$hWnd = WinGetHandle('notepad.exe')

WinActivate($hWnd)
WinWaitActive($hWnd)

MouseClick("Primary",153, 465)

Yes, I know, thanks, but I found somewhere on forums that MouseClick has "forced" 10ms sleep, and there was this example with DllCall etc.

I wanted to try it, and it's really faster :) it's so fast, that apps aren't responding sometimes because there are too many clicks.

[indent=3][/indent]

Link to comment
Share on other sites

What are you trying to accomplish that requires you to click on something faster than 100 times a second?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I don't want to click 100 times a second, just I want to click two buttons checkboxes with minimal delay, and 10ms is too much.

Click(155, 465)
Click(155, 495)
Send("{enter}")

That's all :)

Edited by VixinG

[indent=3][/indent]

Link to comment
Share on other sites

From the help file:

MouseClick ( "button" [, x, y [, clicks [, speed]]] )

Parameters

button The button to click: "left", "right", "middle", "main", "menu", "primary", "secondary". x, y

[optional] The x/y coordinates to move the mouse to. If no x and y coords are given, the current position is used (default). clicks

[optional] The number of times to click the mouse. Default is 1. speed

[optional] the speed to move the mouse in the range 1 (fastest) to 100 (slowest). A speed of 0 will move the mouse instantly. Default speed is 10.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

From here:

@MrCreatoR

No matter what helpfile say what is in my first post is true. I analysed Autoit's 3.1.0 sources to see where is problem when I needed fast clicking in one of my projects. So I discovered this issue and have made this workaround.

In my project clicking worked fine and it was really VERY fast.

I tried with MouseClick() and Zedna's click is really faster. It's so fast, that apps aren't responding if you loop it.

I wouldn't try something like that if it wouldn't be faster.

Am I wrong?

[indent=3][/indent]

Link to comment
Share on other sites

I'm still not sure why 10ms is "too much" when all you need to do is click 2 checkboxes, but in all actuallity I don't really care any longer either. Use whatever you want to click the screen as fast as you want, I'm out.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...