Key to play sound while pressed
Key to play sound while pressed
I know how to play a sound with a hotkey, but is it posible to have a beep sound and keep it sounding as long as you hold that key down, just like the way a car horn works? I think I could make a long wav and make the hotkey detect when the key is relased and at that point interrupt the sound play... Any idea?
-
- Posts: 1259
- Joined: 16 Apr 2015, 09:41
Re: Key to play sound while pressed
To the best of my knowledge, there is no way for AutoHotkey to create an infinitely long sound - the sound length will be limited to the length of the WAV file you create. However, it is certainly possible to play the sound repeatedly while a key is held down (IE: like an alarm - beep beep beep beep). This should work for any length WAV file (or even a simple system beep)...
Code: Select all
F12:: ; Replace this with the key of your choice.
SoundToPlay := "*-1" ; *-1 is the SoundPlay code for the system beep. You can change this to any other SoundPlay code or to a WAV file path & name.
While GetKeyState(A_ThisHotKey, "P")
{
If SoundPlaying
Continue
Else
SetTimer, PlayTheSound, -1
}
SoundPlay, DoesNotExist.avi ; This aborts any currently playing sound file.
Return
PlayTheSound:
SoundPlaying := True
SoundPlay, %SoundToPlay%, Wait
If InStr(SoundToPlay, "*") ; This gives a little time for the system sounds to play, since they ignore the Wait switch.
Sleep 500
SoundPlaying := False
Return
-
- Posts: 1
- Joined: 08 May 2017, 10:41
Re: Key to play sound while pressed
Hello @Shadowpheonix
can I use only to notify on cntl key when pressed?
I tried, but it just work on combination with ! or ^ or +, but they alone it does not work.
e.g; ^d:: is ok but ^:: alone does't work and give the sound!, it considered that as the letter '^' instead of cntl
(because I had a problem in cntl that it does randomly press by its own, i.e; stuck, and I want to check when it does that)
thanks
can I use only to notify on cntl key when pressed?
I tried, but it just work on combination with ! or ^ or +, but they alone it does not work.
e.g; ^d:: is ok but ^:: alone does't work and give the sound!, it considered that as the letter '^' instead of cntl
(because I had a problem in cntl that it does randomly press by its own, i.e; stuck, and I want to check when it does that)
thanks
-
- Posts: 1259
- Joined: 16 Apr 2015, 09:41
Re: Key to play sound while pressed
^ is a special symbol in AutoHotkey which represents the Ctrl key when used in combination with another key. If you want a hotkey that triggers when Ctrl is pressed by itself, you need to use Ctrl::.john_tonson wrote:Hello @Shadowpheonix
can I use only to notify on cntl key when pressed?
I tried, but it just work on combination with ! or ^ or +, but they alone it does not work.
e.g; ^d:: is ok but ^:: alone does't work and give the sound!, it considered that as the letter '^' instead of cntl
(because I had a problem in cntl that it does randomly press by its own, i.e; stuck, and I want to check when it does that)
thanks
Who is online
Users browsing this forum: Bing [Bot] and 102 guests