Reputation: 410
I'm getting two weird warnings.
wx
, wy
, ww
, wh
.ELSE
with no matching IF
", referring to the two if-else
statements.Here's the whole script.
#NoEnv
#Warn
SendMode Input
SetWorkingDir %A_ScriptDir%
screen_scaling_factor := A_ScreenDPI/96
^p::mouse_move_win(200,300)
mouse_move_win(x,y,horizontal:="left",vertical:="top",mouse_click:=""){
wingetpos,wx,wy,ww,wh,a
global screen_scaling_factor
if horizontal="left"{
x1 := wx + x * screen_scaling_factor
}else{
x1 := wx + ww - x * screen_scaling_factor
}
if vertical="top"{
y1 := wy + y * screen_scaling_factor
}else{
y1 := wy + wh - y * screen_scaling_factor
}
DllCall("SetCursorPos", int, x1, int, y1)
}
When I add local
as the first line of the function to enable the "force-local mode", however, the first warning disappears.
When I add a parentheses to the if condition or remove the curly braces following it, as shown below, the second warning disappears.
if (horizontal="left"){
x1 := wx + x * screen_scaling_factor
}else{
x1 := wx + ww - x * screen_scaling_factor
}
or
if horizontal="left"
x1 := wx + x * screen_scaling_factor
else
x1 := wx + ww - x * screen_scaling_factor
Any idea why this is happening?
Upvotes: 0
Views: 432
Reputation: 6489
If you want to use the legacy style if statement (please don't) you can't start your braces from the same line as the if statement. You'd have to drop the starting brace {
down one line.
But please just use the modern expression style if-statement like so:
mouse_move_win(x,y,horizontal:="left",vertical:="top",mouse_click:=""){
wingetpos,wx,wy,ww,wh,a
global screen_scaling_factor
if (horizontal="left"){
x1 := wx + x * screen_scaling_factor
}else{
x1 := wx + ww - x * screen_scaling_factor
}
if (vertical="top"){
y1 := wy + y * screen_scaling_factor
}else{
y1 := wy + wh - y * screen_scaling_factor
}
DllCall("SetCursorPos", int, x1, int, y1)
}
Also, personally I'd call that brace style disgusting, but of course it's just personal preference haha.
But just in case you didn't know, you can omit braces from one liner if/else statements:
mouse_move_win(x,y,horizontal:="left",vertical:="top",mouse_click:="")
{
wingetpos,wx,wy,ww,wh,a
global screen_scaling_factor
if (horizontal="left")
x1 := wx + x * screen_scaling_factor
else
x1 := wx + ww - x * screen_scaling_factor
if (vertical="top")
y1 := wy + y * screen_scaling_factor
else
y1 := wy + wh - y * screen_scaling_factor
DllCall("SetCursorPos", int, x1, int, y1)
}
EDIT: oh seems you edited your post. I started typing this before you edited it, but then I had to go do something.
Anyway, my answer should answer your questions.
Upvotes: 1
Reputation: 1
Use mouse_move_win
(200, 300) instead of mouse_move(200,300)
When you define horizontal:="left", it means Left is its default value, meaning if no value is supplied it assumes it's left. So
if horizontal=left
is unnecessary.
So I guess your code should be other way around with the if and else combos.
^p::mouse_move_win(200, 300)
mouse_move_win(x, y, horizontal:="left", vertical:="top", mouse_click:="") {
wingetpos,wx,wy,ww,wh,a
global screen_scaling_factor
if horizontal=right
x1 := wx + ww - x * screen_scaling_factor
else
x1 := wx + x * screen_scaling_factor
if vertical=bottom
y1 := wy + wh - y * screen_scaling_factor
else
y1 := wy + y * screen_scaling_factor
DllCall("SetCursorPos", int, x1, int, y1)
}
This worked perfectly for me
Upvotes: 0