Help with a simple IF statement

Get help with using AutoHotkey and its commands and hotkeys
RozRoyal
Posts: 24
Joined: 21 Nov 2017, 14:19

Help with a simple IF statement

21 Nov 2017, 16:43

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
A_AhkUser
Posts: 613
Joined: 06 Mar 2017, 16:18
Location: France

Re: Help with a simple IF statement

21 Nov 2017, 17:15

Hi RozRoyal and welcolme to the ahk community.
Here's a simple commented example with notepad.

Code: [Select all] [Download] GeSHi © Codebox Plus

#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
Video Game Reader
Image
github
demo
RozRoyal
Posts: 24
Joined: 21 Nov 2017, 14:19

Re: Help with a simple IF statement

22 Nov 2017, 08:31

Thank you!
Baba Katchka

Re: Help with a simple IF statement

22 Nov 2017, 08:51

A_AhkUser wrote:Hi RozRoyal and welcolme to the ahk community.
Here's a simple commented example with notepad.

Code: [Select all] [Download] GeSHi © Codebox Plus

#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


just curious why you used #ifwinexist over ifwinexist, sorry just trying to learn the difference, the documentation has be confused
Hellbent
Posts: 46
Joined: 23 Sep 2017, 13:34

Re: Help with a simple IF statement

22 Nov 2017, 09:12

Baba Katchka wrote:just curious why you used #ifwinexist over ifwinexist, sorry just trying to learn the difference, the documentation has be confused


By using #ifwinexist he is saying that the hotkey will only work if the condition is met.

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.
RozRoyal
Posts: 24
Joined: 21 Nov 2017, 14:19

Re: Help with a simple IF statement

22 Nov 2017, 10:41

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?

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Image
A_AhkUser
Posts: 613
Joined: 06 Mar 2017, 16:18
Location: France

Re: Help with a simple IF statement

22 Nov 2017, 12:51

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?


I guess it is due to the fact that:
Coordinates are relative to the active window unless CoordMode was used to change that.

source:MouseMove


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)):



You also can choose to substitute both absolute coordinates 1225 and 128 by the relatives one; so that your script will be more reliable since it will work no matter where the window is located.
Video Game Reader
Image
github
demo
RozRoyal
Posts: 24
Joined: 21 Nov 2017, 14:19

Re: Help with a simple IF statement

22 Nov 2017, 13:44

Thank you!
RozRoyal
Posts: 24
Joined: 21 Nov 2017, 14:19

Re: Help with a simple IF statement

22 Nov 2017, 14:13

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)

Code: [Select all] [Download] GeSHi © Codebox Plus

left::click if mouselocation 280, 1045 or 680, 1045 or 780, 1045


The code above does not work : (
Osprey
Posts: 207
Joined: 18 Nov 2017, 05:50

Re: Help with a simple IF statement

22 Nov 2017, 17:07

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:

Code: [Select all] [Download] GeSHi © Codebox Plus

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

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.
A_AhkUser
Posts: 613
Joined: 06 Mar 2017, 16:18
Location: France

Re: Help with a simple IF statement

22 Nov 2017, 20:38

You also can use IfIn when many values can meet a condition:

Code: [Select all] [Download] GeSHi © Codebox Plus

Left::
MouseGetPos, mouseX, mouseY
if (mouseY = 1045)
if mouseX in 280,680,780
MsgBox, test
return
Video Game Reader
Image
github
demo
RozRoyal
Posts: 24
Joined: 21 Nov 2017, 14:19

Re: Help with a simple IF statement

22 Nov 2017, 21:29

Thank you! A_AhkUser and Osprey! : )
RozRoyal
Posts: 24
Joined: 21 Nov 2017, 14:19

Re: Help with a simple IF statement

26 Nov 2017, 22:11

Code: [Select all] [Download] GeSHi © Codebox Plus

Left::
MouseGetPos, mouseX, mouseY
if (mouseY = 1045)
if mouseX in 280,680,780
Click %MouseX%, %MouseY%
return


How can I make the number be in range? For example, look from 80 to 1870?

I tried

Code: [Select all] [Download] GeSHi © Codebox Plus

if mouseX in (1870, 80)

Code: [Select all] [Download] GeSHi © Codebox Plus

if mouseX in (1870-80)
User avatar
jeeswg
Posts: 2982
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Help with a simple IF statement

26 Nov 2017, 22:26

Some possibilities:

Code: [Select all] [Download] GeSHi © Codebox Plus

;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
RozRoyal
Posts: 24
Joined: 21 Nov 2017, 14:19

Re: Help with a simple IF statement

26 Nov 2017, 22:42

Thank you Jeeswg!
RozRoyal
Posts: 24
Joined: 21 Nov 2017, 14:19

Re: Help with a simple IF statement

30 Nov 2017, 23:41

Hey all! Hopefully, someone can help me with this small question.

How can I add an exemption for the below code

Code: [Select all] [Download] GeSHi © Codebox Plus

#IfWinExist rozgrzewka
left::p ;skip to previous song
right::n ;skip to next song
return


to make it work with the main code.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



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.
Last edited by RozRoyal on 01 Dec 2017, 12:36, edited 1 time in total.
RozRoyal
Posts: 24
Joined: 21 Nov 2017, 14:19

Re: Help with a simple IF statement

01 Dec 2017, 12:28

bump, this is the only things missing in my remote script : (
Osprey
Posts: 207
Joined: 18 Nov 2017, 05:50

Re: Help with a simple IF statement

01 Dec 2017, 17:31

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.
RozRoyal
Posts: 24
Joined: 21 Nov 2017, 14:19

Re: Help with a simple IF statement

01 Dec 2017, 19:21

That didn't work : (

Maybe my adding



to Left and Right, might work?

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



But that didn't work.

Return to “Ask For Help”

Who is online

Users browsing this forum: Exaskryz, Frankie158 and 44 guests