Skip to content

How do I get the coordinates of the mouse relative to the program? #292

Answered by spyoungtech
zSynctic asked this question in Q&A
Discussion options

You must be logged in to vote

In AutoHotkey, the behavior of MouseGetPos (.mouse_position or .get_mouse_position() in the ahk python wrapper) is controlled by the current CoordMode setting. If you do not change the CoordMode, the default behavior is to retrieve the coordinates relative to the currently active window.

So, if your program is the active window, there is nothing else you need to do except just call .mouse_position or .get_mouse_position().

In the wrapper, there is two ways to change this behavior:

  1. Use .set_coord_mode to change the global CoordMode setting: ahk.set_coord_mode(target='Mouse', relative_to='Screen')
    OR
  2. Pass the coord_mode parameter to the .get_mouse_position method to set the coord mode just…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by spyoungtech
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants