Want script to only work within designated program.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
realrob
Posts: 8
Joined: 18 Jul 2021, 14:21

Want script to only work within designated program.

Post by realrob » 19 May 2022, 14:31

I have a teeny script to toggle the holding down of my right mouse button.
Is there a way to make it only when a certain application is in focus?


realrob
Posts: 8
Joined: 18 Jul 2021, 14:21

Re: Want script to only work within designated program.

Post by realrob » 19 May 2022, 14:40

boiler wrote:
19 May 2022, 14:34
See #IfWinActive.
Thank you for the reply.
After looking at that, it might as well be in Japanese.
I'm gonna need a ELI5.

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

Re: Want script to only work within designated program.

Post by mikeyww » 19 May 2022, 14:48

Code: Select all

#IfWinActive ahk_exe notepad.exe
F3::Send % GetKeyState("RButton") ? "{RButton up}" : "{RButton down}"
#IfWinActive
Another example

realrob
Posts: 8
Joined: 18 Jul 2021, 14:21

Re: Want script to only work within designated program.

Post by realrob » 19 May 2022, 14:53

mikeyww wrote:
19 May 2022, 14:48

Code: Select all

#IfWinActive ahk_exe notepad.exe
F3::Send % GetKeyState("RButton") ? "{RButton up}" : "{RButton down}"
#IfWinActive
Another example
This was my attempt lol

Code: Select all

#IfWinActive [somename.exe]

toggle=0
return

rbutton::
toggle:=!toggle
if toggle=1
click ,right ,down
else
click, right, up
return
May I ask what the "F3" is for?
I don't have that and it seems to still work.

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

Re: Want script to only work within designated program.

Post by mikeyww » 19 May 2022, 15:01

F3:: is an example of a hotkey. You do not need to use it. Another example of a hotkey is on line 6 of your script.

I recommend moving your #If directive to occur directly above your hotkey, because that is the only place where it works anyway.
Creates context-sensitive hotkeys and hotstrings. Such hotkeys perform a different action (or none at all) depending on the type of window that is active or exists.
See the example that I posted, or :arrow: WinTitle, for proper WinTitle syntax.

realrob
Posts: 8
Joined: 18 Jul 2021, 14:21

Re: Want script to only work within designated program.

Post by realrob » 19 May 2022, 15:13

mikeyww wrote:
19 May 2022, 15:01
F3:: is an example of a hotkey. You do not need to use it. Another example of a hotkey is on line 6 of your script.

I recommend moving your #If directive to occur directly above your hotkey, because that is the only place where it works anyway.
Creates context-sensitive hotkeys and hotstrings. Such hotkeys perform a different action (or none at all) depending on the type of window that is active or exists.
See the example that I posted, or :arrow: WinTitle, for proper WinTitle syntax.
Thank you kindly for the help.
I used your code and implemented a hotkey that works great. Much better than the toggle, to be honest.

Post Reply

Return to “Ask for Help (v1)”