Hotkey If Function

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hemsith14_
Posts: 296
Joined: 07 Nov 2020, 08:37

Hotkey If Function

Post by hemsith14_ » 17 Aug 2022, 19:05

How to get the "test" hotkey to work only when the result of the function is 1 2 3 4 like shown here?

Code: Select all

Hotkey, If, % L(1, 2, 3, 4)
Hotkey, ^1, test


	L(pX1, pY1, pX2, pY2)
	{
		MouseGetPos, LX, LY
		Return (pX1<=LX) && (LX<=pX2) && (pY1<=LY) && (LY<=pY2)
	}
basically, get ^1 to work only if the mouse is over the positions mentioned.
Last edited by hemsith14_ on 17 Aug 2022, 19:59, edited 1 time in total.

User avatar
mikeyww
Posts: 26931
Joined: 09 Sep 2014, 18:38

Re: Hotkey If Function

Post by mikeyww » 17 Aug 2022, 19:53

Is LX a variable name? What is its value when you display it?
Last edited by mikeyww on 17 Aug 2022, 19:58, edited 2 times in total.

hemsith14_
Posts: 296
Joined: 07 Nov 2020, 08:37

Re: Hotkey If Function

Post by hemsith14_ » 17 Aug 2022, 19:57

It works fine if I do

#If L(1, 2, 3, 4)
^1::
;test
return

How do I turn this logic into the hotkey one? Like when you use
Hotkey, IfWinActive

I don't understand how to solve it from
https://www.autohotkey.com/docs/commands/Hotkey.htm#ExampleIfFn
Last edited by hemsith14_ on 17 Aug 2022, 19:58, edited 1 time in total.

User avatar
mikeyww
Posts: 26931
Joined: 09 Sep 2014, 18:38

Re: Hotkey If Function

Post by mikeyww » 17 Aug 2022, 19:58

Is LX a variable name? What is its value when you display it?

See https://www.autohotkey.com/docs/commands/Hotkey.htm#ExampleIfFn
Expression must be an expression which has been used with the #If directive elsewhere in the script. Although this command is unable to create new expressions, it can create new hotkeys using an existing expression.

hemsith14_
Posts: 296
Joined: 07 Nov 2020, 08:37

Re: Hotkey If Function

Post by hemsith14_ » 17 Aug 2022, 20:00

mikeyww wrote:
17 Aug 2022, 19:58
Is LX a variable name? What is its value when you display it?

See https://www.autohotkey.com/docs/commands/Hotkey.htm#ExampleIfFn
Expression must be an expression which has been used with the #If directive elsewhere in the script. Although this command is unable to create new expressions, it can create new hotkeys using an existing expression.
just edited the original post, it's the mouse position
Last edited by hemsith14_ on 17 Aug 2022, 20:02, edited 1 time in total.

User avatar
mikeyww
Posts: 26931
Joined: 09 Sep 2014, 18:38

Re: Hotkey If Function

Post by mikeyww » 17 Aug 2022, 20:02

Please do not go backwards in your posts. How will new readers follow this thread? They will be confused.

See the example that I cited.

Code: Select all

#SingleInstance Force
fn := Func("L").Bind(1, 2, 3, 4)
Hotkey, If, % fn
Hotkey, ^1, Test
Hotkey, If
Return

Test:
MsgBox, Test
Return

L(pX1, pY1, pX2, pY2) {
 MsgBox, %pY1%
 ; Return False
 Return True
}

Post Reply

Return to “Ask for Help (v1)”