How to make an IF statement
when number 1 is pressed AND the program is running (test.xspf) move the mouse to x location
if (test.xspf) is not then open when number 1 is pressed than run the file (test.xspf)
If someone could help me with this I would be truly grateful!
Here is where my test.xspf is if that helps
1::Run, C:\Users\Andrew\Desktop\test.xspf
Help with a simple IF statement
Re: Help with a simple IF statement
Hi RozRoyal and welcolme to the ahk community.
Here's a simple commented example with notepad.
references:
#If (context-sensitive hotkey)
win title parameter
Here's a simple commented example with notepad.
Code: Select all
#IfWinExist ahk_exe notepad.exe ; create a context-sensitive hotkey depending on the wintitle parameter specified (here any window which belongs to notepad process - modify it to make it fit your purpose)
1::MouseMove, 0, 0 ;
#IfWinNotExist ahk_exe notepad.exe ; change the context-sensitivity for subsequently created hotkeys
1::
run, notepad
MsgBox, test
return ; if a hotkey needs to execute more than on line, those lines cannot be listed to the right of the double-colon nor should be placed beneath it and a return used to finish the subroutine
#If ; turn off context sensitivity
references:
#If (context-sensitive hotkey)
win title parameter
Re: Help with a simple IF statement
Thank you!
Re: Help with a simple IF statement
just curious why you used #ifwinexist over ifwinexist, sorry just trying to learn the difference, the documentation has be confusedA_AhkUser wrote:Hi RozRoyal and welcolme to the ahk community.
Here's a simple commented example with notepad.
Code: Select all
#IfWinExist ahk_exe notepad.exe ; create a context-sensitive hotkey depending on the wintitle parameter specified (here any window which belongs to notepad process - modify it to make it fit your purpose) 1::MouseMove, 0, 0 ; #IfWinNotExist ahk_exe notepad.exe ; change the context-sensitivity for subsequently created hotkeys 1:: run, notepad MsgBox, test return ; if a hotkey needs to execute more than on line, those lines cannot be listed to the right of the double-colon nor should be placed beneath it and a return used to finish the subroutine #If ; turn off context sensitivity
references:
#If (context-sensitive hotkey)
win title parameter
Re: Help with a simple IF statement
By using #ifwinexist he is saying that the hotkey will only work if the condition is met.Baba Katchka wrote: just curious why you used #ifwinexist over ifwinexist, sorry just trying to learn the difference, the documentation has be confused
with it set up that way, pressing 1 in any other window will do what it normally would do, and the hotkey would only become active in the targeted window.
Re: Help with a simple IF statement
I have a small issue, I want to double-click on a location 1225, 128 (that would be on the playlist) but for some reason, it clicks down-left of the screen...
Why is this the case?
Why is this the case?
Code: Select all
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
#IfWinExist Playlist ahk_class QWidget
1::Click 2, 1225, 128
#IfWinNotExist ahk_exe vlc.exe
1::run, C:\Users\Andrew\Desktop\test.xspf
return
#If
Re: Help with a simple IF statement
I guess it is due to the fact that:RozRoyal wrote:I have a small issue, I want to double-click on a location 1225, 128 (that would be on the playlist) but for some reason, it clicks down-left of the screen...
Why is this the case?
source:MouseMoveCoordinates are relative to the active window unless CoordMode was used to change that.
So, using CoordMode you'll be able to set coordinates to be relative to the screen (top-left part of your screen as origin (0, 0)):
Code: Select all
CoordMode, Mouse, Screen
Re: Help with a simple IF statement
Thank you!
Re: Help with a simple IF statement
I'm so almost done with my first script! Thank you AhkUser for your help!
Just one more thing I think haha
When I press left key I want it to ONLY click if the mouse cursor is in one of the 3 locations (280, 1045 or 680, 1045 or 780, 1045)
The code above does not work : (
Just one more thing I think haha
When I press left key I want it to ONLY click if the mouse cursor is in one of the 3 locations (280, 1045 or 680, 1045 or 780, 1045)
Code: Select all
left::click if mouselocation 280, 1045 or 680, 1045 or 780, 1045
Re: Help with a simple IF statement
I suggest that you make use of the help file (AutoHotkey.chm) that comes with AutoHotkey to lean the syntax of commands and which commands you can use, so that you aren't just stumbling in the dark and guessing at them. For now, though, the following seems to be what you want:
I suggest looking up the MouseGetPos, If and Click commands in the help file (you can also click on them above) to familiarize yourself with them so that you understand what the above code does and how you might modify it to do something different.
Code: Select all
left::
MouseGetPos, MouseX, MouseY
If ((MouseX = 280) and (MouseY = 1045)) or ((MouseX = 680) and (MouseY = 1045)) or ((MouseX = 780) and (MouseY = 1045))
Click %MouseX%, %MouseY%
return
Re: Help with a simple IF statement
I will! Thank YOU!!!
Re: Help with a simple IF statement
You also can use IfIn when many values can meet a condition:
Code: Select all
Left::
MouseGetPos, mouseX, mouseY
if (mouseY = 1045)
if mouseX in 280,680,780
MsgBox, test
return
Re: Help with a simple IF statement
Thank you! A_AhkUser and Osprey! : )
Re: Help with a simple IF statement
Code: Select all
Left::
MouseGetPos, mouseX, mouseY
if (mouseY = 1045)
if mouseX in 280,680,780
Click %MouseX%, %MouseY%
return
I tried
Code: Select all
if mouseX in (1870, 80)
Code: Select all
if mouseX in (1870-80)
Re: Help with a simple IF statement
Some possibilities:
Code: Select all
;if vNum between %vLim1% and %vLim2%
Between(vNum, vLim1, vLim2)
{
return (vNum >= vLim1 && vNum <= vLim2)
}
if (mouseX >= 1870 && mouseX <= 1880)
if mouseX between 1870 and 1880 ;due to be removed in AHK v2
if Between(mouseX, 1870, 1880) ;requires a custom function
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Help with a simple IF statement
Thank you Jeeswg!
Re: Help with a simple IF statement
Hey all! Hopefully, someone can help me with this small question.
How can I add an exemption for the below code
to make it work with the main code.
What I want is to skip the songs using buttons (left or right) only if the window (Rozgrzewka) exists.
If it doesn't exist then the main code works.
Thank you.
How can I add an exemption for the below code
Code: Select all
#IfWinExist rozgrzewka
left::p ;skip to previous song
right::n ;skip to next song
return
Code: Select all
Between(vNum, vLim1, vLim2)
{
return (vNum >= vLim1 && vNum <= vLim2)
}
Left::
MoeGetPos, mouseX, mouseY
#if (mouseY = 1045)
#if (mouseX >= 80 && mouseX <= 1860)
Click %MouseX%, %MouseY%
return
right::toggle:=!toggle
#if toggle
up::Send {+}
down::Send {-}
#if !toggle
up::Send {Volume_Up}
down::Send {Volume_Down}
#if
#IfWinExist Polka_nr_13.mp3
1::click 80, 1045
2::click 880, 1045
3::click 980, 1045
return
If it doesn't exist then the main code works.
Thank you.
Last edited by RozRoyal on 01 Dec 2017, 12:36, edited 1 time in total.
Re: Help with a simple IF statement
bump, this is the only things missing in my remote script : (
Re: Help with a simple IF statement
If you're saying that combining the two sets of code makes the second set not execute, it may be because you have "return" in the first set. Remove that.
Last edited by Osprey on 01 Dec 2017, 20:26, edited 1 time in total.
Re: Help with a simple IF statement
That didn't work : (
Maybe my adding
to Left and Right, might work?
But that didn't work.
Maybe my adding
Code: Select all
#IfWinNotExist Rozgrzewka
Code: Select all
Left::
#IfWinNotExist Rozgrzewka ; < ------------------- HERE
MoeGetPos, mouseX, mouseY
#if (mouseY = 1045)
#if (mouseX >= 80 && mouseX <= 1860)
Click %MouseX%, %MouseY%
return
right::toggle:=!toggle
#IfWinNotExist Rozgrzewka ; < ------------------- HERE
#if toggle
up::Send {+}
down::Send {-}
#if !toggle
up::Send {Volume_Up}
down::Send {Volume_Down}
#if