I have computers with different display settings and want to be able to move the cursor for different button positions using the same script by only changing one value. The screen display settings for the OtherDisplayX and OtherDisplayY may also change at a later time so I'm trying to avoid large changes in the future. The development is being done on the laptop. The issue is I cannot seem to get it to do the calculation correctly and I must admit I'm struggling with the syntax.
To observe my problem, changing the parameter OtherDisplay between 0 and 1 below is what I had hoped to do.
!1:: ;alt+1 hotkey to run
#SingleInstance, Force ;if there is another version running, stop it and run new version
;The purpose of this script is to use the same script for computers with different
;display settings by changing 1 value. Screen coordinates are used because the window name
;is sometimes not easily discovered or provided.
; Use screen coordinantes for mouse, not window
CoordMode,Mouse,Screen
OtherDisplay=0 ;Change OtherDisplay to 1 to use OtherDisplayX and OtherDisplayY values
;Variables to modify if displat size changes at a later date
LaptopDisplayX=1366
LaptopDisplayY=768
OtherDisplayX=1600
OtherDisplayY=900
;~ The calculation being performed is:
;~ Add this line after ever XVal = nnn statement
;~ If Other (XVal = XVal * OtherDisplayX / LaptopDisplayX)
;~ Add this line after ever YVal = nnn statement
;~ If Other (YVal = YVal * OtherDisplayY / LaptopDisplayY)
;~ Below is an example of one button press, there are 25
TargetButtonX=683 ;this line is added for every X button coordinance
If(OtherDisplay) {
TargetButtonX = Round(TargetButtonX * OtherDisplayX / LaptopDisplayX)
}
MsgBox, %TargetButtonX%
TargetButtonY=384 ;this line is added for every Y button coordinance
If(OtherDisplay) {
TargetButtonY = Round(TargetButtonY * OtherDisplayY / LaptopDisplayY)
}
MsgBox, %TargetButtonY%
MouseMove, TargetButtonX, TargetButtonY
!2::ExitApp
How to calculate mouse position for machines with different display settings
Re: How to calculate mouse position for machines with different display settings
Hallo,
just use MouseMove(X,Y) on all machines:or the factors Sx, Sy:
just use MouseMove(X,Y) on all machines:
Code: Select all
CoordMode,Mouse,Screen
Global LaptopDisplayX, LaptopDisplayY
LaptopDisplayX=1366
LaptopDisplayY=768
Return
!1:: ;alt+1 hotkey to run
MouseMove(683,384)
Return
MouseMove(X,Y)
{ ;MouseMove(TargetButtonX,TargetButtonY)
MouseMove,% X*A_ScreenWidth//LaptopDisplayX
,Y*A_ScreenHeight//LaptopDisplayY
}
Code: Select all
CoordMode,Mouse,Screen
Global Sx, Sy
Sx := A_ScreenWidth/1366
Sy := A_ScreenHeight/768
Return
!1:: ;alt+1 hotkey to run
MouseMove,% 683*Sx, 384*Sy
Return
Re: How to calculate mouse position for machines with different display settings
Thanks very much, your way is better. I didn’t think to look for global screen settings.
I was spending all my time trying to decide why I couldn’t get the TargetButtonX and TargetButtonY equations to work, and still haven’t. Using the debug feature in the editor seemed to give me confusing results as instead of showing a result from the equation it shows all the individual values.
I was spending all my time trying to decide why I couldn’t get the TargetButtonX and TargetButtonY equations to work, and still haven’t. Using the debug feature in the editor seemed to give me confusing results as instead of showing a result from the equation it shows all the individual values.
Re: How to calculate mouse position for machines with different display settings
I do have another question. Can you explain the MouseMove, % syntax?
Re: How to calculate mouse position for machines with different display settings
Hallo,
in https://autohotkey.com/docs/Variables.htm#Expressions
Force an expression: An expression can be used in a parameter that does not directly support it (except OutputVar parameters) by preceding the expression with a percent sign and a space or tab. …
in https://autohotkey.com/docs/Variables.htm#Expressions
Force an expression: An expression can be used in a parameter that does not directly support it (except OutputVar parameters) by preceding the expression with a percent sign and a space or tab. …
Re: How to calculate mouse position for machines with different display settings
Thank you, great! ... and Fast, much appreciated.
Who is online
Users browsing this forum: No registered users and 119 guests