How can we go back to DEFAULT Coordmode mode?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
GEOVAN
Posts: 182
Joined: 03 Mar 2022, 11:12

How can we go back to DEFAULT Coordmode mode?

07 May 2024, 10:40

Hello,

Lets say that i want to use the CoordMode, for example as follow:

CoordMode, Mouse ,Screen
MouseGetPos, MX, MY
....SOME CODE......

Now, lets say that i want to go back to DEFAULT Coordmode mode.
How can i do it, please?
User avatar
mikeyww
Posts: 27169
Joined: 09 Sep 2014, 18:38

Re: How can we go back to DEFAULT Coordmode mode?

07 May 2024, 11:05

Use Window instead of Screen.
GEOVAN
Posts: 182
Joined: 03 Mar 2022, 11:12

Re: How can we go back to DEFAULT Coordmode mode?

07 May 2024, 12:13

Thank you very much,

So:

CoordMode, Mouse ,Screen
MouseGetPos, MX, MY
....SOME CODE......
CoordMode, Mouse ,Window


The last line --> CoordMode, Mouse ,Window ---> will force the SCRIPT to go back to DEFAULT state, that is to the state it was before using the CoordMode, Mouse ,Screen


But, in a case i will use the RETURN instead of the CoordMode, Mouse ,Window, for example as follow:
CoordMode, Mouse ,Screen
MouseGetPos, MX, MY
....SOME CODE......
RETURN


Will this result to the same, that is ------> will this result the SCRIPT to go back to DEFAULT state, that is to the state it was before using the CoordMode, Mouse ,Screen ?
User avatar
boiler
Posts: 17184
Joined: 21 Dec 2014, 02:44

Re: How can we go back to DEFAULT Coordmode mode?

07 May 2024, 12:16

If you want to go back to whatever the previous coord mode was without knowing what it was, you can do this:

Code: Select all

PrevCoordModeMouse := A_CoordModeMouse
CoordMode, Mouse ,Screen
MouseGetPos, MX, MY
....SOME CODE......
CoordMode, Mouse, % PrevCoordModeMouse

It doesn’t matter if you use a Return or not because you’re only affecting the current thread anyway. If your code was a new thread, you didn’t affect the coord mode of the thread it interrupted.

Restoring it to the prior state is good for functions which could be called from various places in a script that could have set the coord mode differently and would like to continue as if it weren’t changed. It’s also good for writing general-use functions so that they are good citizens and don’t disrupt the script’s settings when the script may not be aware of potential changes and not expecting them to change.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 111 guests