Help with a simple IF statement

Post a reply

Confirmation code
Enter the code exactly as it appears. All letters are case insensitive.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Help with a simple IF statement

Re: Help with a simple IF statement

Post by Osprey » 01 Dec 2017, 20:32

You're using the #IfWinNotExist and #If directives all incorrectly. See the help file and, especially, the examples section at the bottom.

Re: Help with a simple IF statement

Post by RozRoyal » 01 Dec 2017, 19:21

That didn't work : (

Maybe my adding



to Left and Right, might work?

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



But that didn't work.

Re: Help with a simple IF statement

Post by Osprey » 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.

Re: Help with a simple IF statement

Post by RozRoyal » 01 Dec 2017, 12:28

bump, this is the only things missing in my remote script : (

Re: Help with a simple IF statement

Post by RozRoyal » 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]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]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.

Re: Help with a simple IF statement

Post by RozRoyal » 26 Nov 2017, 22:42

Thank you Jeeswg!

Re: Help with a simple IF statement

Post by jeeswg » 26 Nov 2017, 22:26

Some possibilities:

Code: [Select all]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

Re: Help with a simple IF statement

Post by RozRoyal » 26 Nov 2017, 22:11

Code: [Select all]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]GeSHi © Codebox Plus

if mouseX in (1870, 80)

Code: [Select all]GeSHi © Codebox Plus

if mouseX in (1870-80)

Re: Help with a simple IF statement

Post by RozRoyal » 22 Nov 2017, 21:29

Thank you! A_AhkUser and Osprey! : )

Re: Help with a simple IF statement

Post by A_AhkUser » 22 Nov 2017, 20:38

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

Code: [Select all]GeSHi © Codebox Plus

Left::
MouseGetPos, mouseX, mouseY
if (mouseY = 1045)
if mouseX in 280,680,780
MsgBox, test
return

Re: Help with a simple IF statement

Post by Guest » 22 Nov 2017, 19:40

I will! Thank YOU!!!

Re: Help with a simple IF statement

Post by Osprey » 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]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.

Re: Help with a simple IF statement

Post by RozRoyal » 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]GeSHi © Codebox Plus

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


The code above does not work : (

Re: Help with a simple IF statement

Post by RozRoyal » 22 Nov 2017, 13:44

Thank you!

Re: Help with a simple IF statement

Post by A_AhkUser » 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.

Re: Help with a simple IF statement

Post by RozRoyal » 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]GeSHi © Codebox Plus



Image

Re: Help with a simple IF statement

Post by Hellbent » 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.

Re: Help with a simple IF statement

Post by Baba Katchka » 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]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

Re: Help with a simple IF statement

Post by RozRoyal » 22 Nov 2017, 08:31

Thank you!

Re: Help with a simple IF statement

Post by A_AhkUser » 21 Nov 2017, 17:15

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

Code: [Select all]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

Top