Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Get / Store CoordMode Setting


  • Please log in to reply
22 replies to this topic
a4u
  • Guests
  • Last active:
  • Joined: --
Is there any way get the current coordmode setting of a script? Specifically for the mouse. I want to change the coordmode setting in a function for moving the mouse, but then restore it to the previous setting.

TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006
You could do something like this ( only tested tooltip ):
setBatchLines 1
loop
  tooltip % coordStat( "tooltip", "screen" ), 10, 10

coordStat( mode, relPos="" ) { ; defaults to screen if relPos misspelled or omitted.
  coordMode, % mode, % ( !( inStr( relPos, "screen" )
								 || inStr( relPos, "relative" ) )
								 ?  "Screen" : relPos )
  return mode
}
esc::exitApp
You'd have to somehow take new threads into consideration for it to actually work 100% ( I think ).
If your the real a4u, this question seems weird coming from you :?

Posted Image

don't duplicate, iterate!


Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009
No.

AHK_L wish list: A_CoordModeToolTip, A_CoordModePixel, A_CoordModeMouse

TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006
What about adding a global var A_CoordMode:=mode to the above function??

Posted Image

don't duplicate, iterate!


a4u
  • Guests
  • Last active:
  • Joined: --

If your the real a4u, this question seems weird coming from you :?

I was gonna mention this is my first thread I started to ask a question :p . Anyways, your function modifies the script's coordmode setting without setting it back.

I was hoping to accomplish this without using a label, since it's meant to be a function for other scripts:
MouseMove, 10, 10
MsgBox
MoveMouse(10, 10)
MsgBox
MouseMove, 10, 10
return

MoveMouse(x, y) {
	global MoveMouse_x, MoveMouse_y
	MoveMouse_x := x, MoveMouse_y := y
	SetTimer, MoveMouse_label, -10
}
	MoveMouse_label:
	CoordMode, Mouse, Screen
	MouseMove, %MoveMouse_x%, %MoveMouse_y%
	return


TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006
Whoa I'm against timers in functions. It may be ok though.. not sure..

Posted Image

don't duplicate, iterate!


tomoe_uehara
  • Members
  • 2166 posts
  • Last active: Jun 11 2015 05:33 PM
  • Joined: 05 Sep 2009

If your the real a4u, this question seems weird coming from you :?

Yep, he should rename himself to q4u first :lol:

a4u
  • Guests
  • Last active:
  • Joined: --

Yep, he should rename himself to q4u first :lol:

Is it weird that we were thinking the same thing :wink:

I suppose something like this would be acceptable, since it doesn't use globals, and it only uses the one label:
MoveMouse(p1,p2) {
	static x, y
	x:=p1, y:=p2
	SetTimer, MoveMouse_label, -10
	return
	[color=brown]MoveMouse_label:[/color]
	CoordMode, Mouse, Screen
	MouseMove, %x%, %y%
	return
}


None
  • Members
  • 3199 posts
  • Last active: Nov 05 2015 09:55 PM
  • Joined: 28 Nov 2009
CoordMode, Mouse, Screen

Moveto(20,20)

Sleep 500

CoordMode, Mouse, Relative

Moveto(20,40)

Return



Moveto(xin,yin) {

WinGetPos , X, Y,,,A

MouseGetPos, xw, yw

MouseMove, xin-(x+xw), yin-(y+yw) , 0, R ;move to calculated point if mode is reltive

MouseGetPos, xc, yc

If (xin-(x+xc)<>0) || (yin-(y+yc)<>0) ;if pos is not right (your mode is screen)

 MouseMove xin, yin,0 ;move to absolute

}
You could move it twice if the first pos is not correct :)

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
MoveMouse( A_ScreenWidth/2, A_ScreenHeight/2 ) ; place mouse cursor in center 



MoveMouse( x,y ) {

 Return DllCall( "SetCursorPos", Int,x, Int,y )

}


a4u
  • Guests
  • Last active:
  • Joined: --
Thanks SKAN - that's what I needed :D . Here's the final function - which is being used here:
PlaySMR(script, relative="") {

   batchLines := A_BatchLines

   SetBatchLines, -1

   if relative

      WinGetPos, x, y, , , A

   else, x:=y:=0

   Loop, Parse, script, |

      if RegExMatch(A_LoopField,"(\d+)&(\d+)",p) {

         DllCall("SetCursorPos", "Int",x+p1, "Int",y+p2)

         Sleep, 10

      } else,

         Send, {%A_LoopField%}

   SetBatchLines, %batchLines%

}


TLM
  • Administrators
  • 3864 posts
  • Last active:
  • Joined: 21 Aug 2006

your function modifies the script's coordmode setting without setting it back.

I believe an Exit in the function would have done the trick ( still going to test it ).
Oh well glad to hear you figured it out,
q4u created a strange imbalance in the universe :)..

Posted Image

don't duplicate, iterate!


MasterFocus
  • Moderators
  • 4323 posts
  • Last active: Jan 28 2016 01:38 AM
  • Joined: 08 Apr 2009

since it doesn't use globals

Even if your label is "inside" your function, its variables shall be global.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Antonio Fran├ža -- git.io -- github.com -- ahk4.net -- sites.google.com -- ahkscript.org

Member of the AHK community since 08/Apr/2009. Moderator since mid-2012.


a4u
  • Guests
  • Last active:
  • Joined: --
:?: - I don't follow:
Func()

MsgBox, 0, Main Script, %x%



Func() {

   static x := 5

   SetTimer, Label, -10

   return

   label:

   MsgBox, 0, Label, %x%

   return

}


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Callbacks can give a little more control if all you want is to run some code in a new thread:
cb := RegisterCallback("MyNewThread")
DllCall(cb, "int", 123)
DllCall("GlobalFree", "ptr", cb)  ; ptr: AutoHotkey_L required.
MsgBox % "BatchLines " A_BatchLines

MyNewThread(param) {
    SetBatchLines -1
    MsgBox % "BatchLines " A_BatchLines " | param " param
}