Hold key if window is active Topic is solved
-
- Posts: 6
- Joined: 16 May 2022, 16:43
Hold key if window is active
Hi all,
Seemingly simple task here but I can't quite figure it out (am quite a novice with AHK). How do I create a script that holds down a key simply by virtue of a window being active? I'm already using #IfWinActive to rebind various other keys here, but I can't figure out how to just have a persistent "key down" action without assigning to some kind of physical key press on my part first.
Any help will be appreciated.
Seemingly simple task here but I can't quite figure it out (am quite a novice with AHK). How do I create a script that holds down a key simply by virtue of a window being active? I'm already using #IfWinActive to rebind various other keys here, but I can't figure out how to just have a persistent "key down" action without assigning to some kind of physical key press on my part first.
Any help will be appreciated.
Re: Hold key if window is active Topic is solved
Code: Select all
#SingleInstance Force
Loop {
WinWaitActive, ahk_exe notepad.exe
Send {x down}
SoundBeep, 1500
WinWaitNotActive
Send {x up}
SoundBeep, 1000
}
-
- Posts: 6
- Joined: 16 May 2022, 16:43
Re: Hold key if window is active
Hey Mikey, thanks for the speedy response. The code you provided does not seem to be working though (tested with Notepad using the code provided and in-game).
Any chance there's something that's been omitted?
Any chance there's something that's been omitted?
Re: Hold key if window is active
Did this script alone work in Notepad, with no other code? It shows a single "x" when you switch to Notepad.
-
- Posts: 6
- Joined: 16 May 2022, 16:43
Re: Hold key if window is active
I was just about to report back that it actually does seem to work when the I ran the script in a completely new file without any other scripts in there.
The issue is that ideally I'd need to get it working as part of my AHK master file which contains various other scripts. Is there any easy fix for this? I can send through the full contents of the master file if that's of help. Nothing super complicated in there, just a list of different #IfWinActive with a handful of remaps for each one.
The issue is that ideally I'd need to get it working as part of my AHK master file which contains various other scripts. Is there any easy fix for this? I can send through the full contents of the master file if that's of help. Nothing super complicated in there, just a list of different #IfWinActive with a handful of remaps for each one.
Re: Hold key if window is active
Sure, post it. As I think you proved, the issue is how you assembled the script. In the meantime, you can read documentation about auto-execute. Unlabeled code following Return is unreachable and will never execute.
-
- Posts: 6
- Joined: 16 May 2022, 16:43
Re: Hold key if window is active
Hey Mikey,
I managed to arrive at a solution that doesn't require any further changes to your code in the end, so marking this as the answer. Thanks again for providing the solution!
I managed to arrive at a solution that doesn't require any further changes to your code in the end, so marking this as the answer. Thanks again for providing the solution!