During a portion of my script, I would like to listen for certain keys to be hit. If those keys are hit, I want a wav file to be played. the keys to be hit can come in any order so it looks like I can't use waitkeydown.
How can I have macro scheduler listen for any key?
for example:
listenforkey
if> A pressed
playwav
endif
if> S pressed
playwav
endif
if> D pressed
playwav
endif
etc.
I always appreciate your help.
play sound when certain keys are hit
Moderators: Dorian (MJT support), JRL
Code: Select all
//Plays the tone when an "a" or "A" is pressed
OnEvent>Key_Down,A,0,Tone
Let>ToneFlag=0
Label>Loop
Wait>0.01
//The use of the flag prevents the tone from playing repetitively
//when the key is held down
If>ToneFlag>0
Add>ToneFlag,1
If>ToneFlag>3
Let>ToneFlag=0
EndIF
EndIf
Goto>Loop
SRT>Tone
If>ToneFlag=0
//Substitute a wav file if you'd rather
LibFunc>kernel32,Beep,Bres,600,50
EndIF
Let>ToneFlag=1
END>Tone
In this example I have OnEvent set to play a wav file.
Virtual key codes (VK) are located here http://www.mjtnet.com/vkcodes.htm
I hope this helps.
Virtual key codes (VK) are located here http://www.mjtnet.com/vkcodes.htm
I hope this helps.
Code: Select all
OnEvent>KEY_DOWN,VK65,0,Key_A
OnEvent>KEY_DOWN,VK66,0,Key_B
OnEvent>KEY_DOWN,VK67,0,Key_C
OnEvent>KEY_DOWN,VK68,0,Key_D
OnEvent>KEY_DOWN,VK69,0,Key_E
OnEvent>KEY_DOWN,VK70,0,Key_F
Label>Loop
Wait>.1
Goto>Loop
SRT>Key_A
PlayWav>C:\Audio\Wav\A.wav
END>Key_A
SRT>Key_B
PlayWav>C:\Audio\Wav\B.wav
END>Key_B
SRT>Key_C
PlayWav>C:\Audio\Wav\C.wav
END>Key_C
SRT>Key_D
PlayWav>C:\Audio\Wav\D.wav
END>Key_D
SRT>Key_E
PlayWav>C:\Audio\Wav\E.wav
END>Key_E
SRT>Key_F
PlayWav>C:\Audio\Wav\F.wav
END>Key_F