Play a sound under a specific situation

Ask gaming related questions (AHK v1.1 and older)
oSheaths
Posts: 13
Joined: 30 Jul 2022, 12:40

Play a sound under a specific situation

Post by oSheaths » 19 Aug 2022, 09:39

How do I make a script that plays a custom sound in this situation:

A timer starts whenever I left click. It is cancelled in 0.4 seconds or if I left click again
The timer won't get cancelled by these 2 things if I press these keys in this order: 5 > Right click > 6
After 0.5 seconds a custom sound plays and the timer ends

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

Re: Play a sound under a specific situation

Post by mikeyww » 19 Aug 2022, 21:09

Some ideas are below, may need adjusting.

Code: Select all

#InstallKeybdHook
~RButton::keep := A_PriorKey = 5
~6::keep := keep && A_PriorKey = "RButton"
~LButton::
If on := !on {
 SetTimer, Reset, -400
 SetTimer, Play, -500
} Else Gosub, Reset
ToolTip, %on%
Return

Play:
SoundPlay, %A_WinDir%\Media\Windows Background.wav
keep := False
Reset:
If !keep {
 SetTimer, Play, Off
 on := False
 SoundBeep, 1000
}
ToolTip, %on%
Return

oSheaths
Posts: 13
Joined: 30 Jul 2022, 12:40

Re: Play a sound under a specific situation

Post by oSheaths » 20 Aug 2022, 08:59

@mikeyww The entire game mechanic the script is designed for goes like this: Left click (starts the script) > 5 > Right click > 6 > Right click > And then Left click > Right click x2
The thing is that the script won't work after 6. The script only checks for 5 > Right click > 6 just in case if I make a mistake after that somehow. Do you wanna make it so that the script checks for the entire mechanic except for the last right click Mikey?

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

Re: Play a sound under a specific situation

Post by mikeyww » 20 Aug 2022, 09:41

You may be able to do that. One approach is to check the A_PriorKey in each case, to validate the sequence along the way. Examples are on lines 2 & 3. You may be able to extend the approach. Good luck.

oSheaths
Posts: 13
Joined: 30 Jul 2022, 12:40

Re: Play a sound under a specific situation

Post by oSheaths » 20 Aug 2022, 10:04

@mikeyww Ah that's impossible since I'm new to this and I have barely any idea what I am doing. But thank you very much for the help Mikey, I won't bother you no more

oSheaths
Posts: 13
Joined: 30 Jul 2022, 12:40

Re: Play a sound under a specific situation

Post by oSheaths » 20 Aug 2022, 10:23

I also changed the time it gets cancelled from 0.4 seconds to 0.499 seconds if that is relevant

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

Re: Play a sound under a specific situation

Post by mikeyww » 20 Aug 2022, 10:29

That's OK. Could be a learning opportunity at hand! :)

oSheaths
Posts: 13
Joined: 30 Jul 2022, 12:40

Re: Play a sound under a specific situation

Post by oSheaths » 20 Aug 2022, 20:47

Bump

Post Reply

Return to “Gaming Help (v1)”