Hotstring() via RButton only calling function (with parameters?) Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hotkeyguy
Posts: 170
Joined: 11 Oct 2014, 12:22

Hotstring() via RButton only calling function (with parameters?)

Post by hotkeyguy » 28 Oct 2021, 11:08

Hello again,

I want to control the behaviour of an running script for some seconds via the right mouse button. Hotstring() should call a function, when possible with parameters. I tried different RButton-"syntax" without success. I'm aware of option X (Execute) for calling a function.
Any hints are highly appreciated!


Many thanks and greetings
hotkeyguy

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

Re: Hotstring() via RButton only calling function (with parameters?)

Post by mikeyww » 28 Oct 2021, 11:31

Be specific. Exactly what will you do as the user? Exactly what will the script do in response? Explain, step by step. Include an example.

hotkeyguy
Posts: 170
Joined: 11 Oct 2014, 12:22

Re: Hotstring() via RButton only calling function (with parameters?)

Post by hotkeyguy » 28 Oct 2021, 12:40

1. Using RButton as hotstring directly, calling a function, works:

Code: Select all

RButton::
  HotFct()
return

HotFct()
{
  MsgBox, , Hotstring, Triggered!
}
2. HotString()-function, with hotstring "rb " works - but I want to use the right mouse button (RButton) as trigger, no text. Due to my requirement, I must be able to switch the hotstring on and off, therefore the use of the HotString()-function.

Code: Select all

HotString( ":X:rb", "HotFct", "On" )
return

HotFct()
{
  MsgBox, , Hotstring, Triggered!
}
3. Is it possible to pass parameters to HotFct()?

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

Re: Hotstring() via RButton only calling function (with parameters?)  Topic is solved

Post by mikeyww » 28 Oct 2021, 12:44

Hotstrings are for text strings, not buttons. You can add a Hotkey command to your first script. It is analogous to Hotstring() but for hotkeys.

Code: Select all

Gosub, F3

F3::
Hotkey, RButton, RB1, On
SoundBeep, 1500
Return

F4::
Hotkey, RButton, RB2, On
SoundBeep, 1200
Return

F5::
Hotkey, RButton, Off
SoundBeep, 900
Return

RB1:
HotFct("Definitely triggered!")
Return

RB2:
HotFct("Really triggered!")
Return

HotFct(str)
{
 MsgBox, 64, Hotstring, %str%
}
Or:

Code: Select all

F3::
F4::
fn := Func("HotFct").Bind(A_ThisHotkey)
Hotkey, RButton, %fn%, On
SoundBeep, 1500
Return

F5::
Hotkey, RButton, Off
SoundBeep, 1000
Return

HotFct(str)
{
 MsgBox, 64, Hotstring, %str%
}
Or:

Code: Select all

F3::
F4::
str := A_ThisHotkey, on := True
SoundBeep, 1500
Return

F5::
on := False
SoundBeep, 1000
Return

#If on
RButton::HotFct(str)
#If

HotFct(str)
{
 MsgBox, 64, Hotstring, %str%
}

hotkeyguy
Posts: 170
Joined: 11 Oct 2014, 12:22

Re: Hotstring() via RButton only calling function (with parameters?)

Post by hotkeyguy » 28 Oct 2021, 13:01

Many thanks mikeyww for rerailing, I was confused Hotstring vs. Hotkey!

Post Reply

Return to “Ask for Help (v1)”