使用自动热键播放小键盘中按下的数字
Play digits pressed in numpad using autohotkey
当我在小键盘上按下数字时,我需要播放所按下数字的波形文件。
我使用了下面的代码
~Numpad1::SoundPlay, 1.wav, wait
return
~Numpad2::SoundPlay, 2.wav , wait
return
~Numpad3::SoundPlay, 3.wav, wait
return
当我单独按下每个数字时,它播放得很好。但是当我依次按下 123 时,我只能听到最后一波(所以当按下 123 时,我只能听到 3.wav)。我需要按顺序听到“一二三”,有什么办法吗?
If a file is playing and the current script plays a second file, the first file will be stopped so that the second one can play. On some systems, certain file types might stop playing even when an entirely separate script plays a new file.
听起来为您的热键制作单独的脚本是您可以尝试的唯一简单解决方案。
更高级的解决方案将包括更多地手动使用内部 Windows(或外部)功能来播放具有更多控制的声音。
例如。可以使用 Run command 在声音播放器中启动音频文件。我想说任何体面的声音播放器都可以从命令行参数播放声音。即使您没有看到屏幕上弹出任何声音播放器,也可能可以做到这一点。 (如果不是我想它也可以手动隐藏)
编辑:
可能理解错了问题,我的回答是同时播放多个声音。
为了解决这个问题,我使用数组作为缓冲区来捕获输入。然后,我让脚本获取数组的第一个元素,在开关中使用它来确定要播放的声音,然后删除我们正在使用的第一个元素,以便继续播放缓冲区中的下一个声音。如果我刚才说的没有多大意义,代码本身可能更容易理解。
代码如下:
#SingleInstance Force
Buffer:=[]
Loop{
Loop 1{
tempVar := Buffer[A_Index]
Buffer.Remove(A_Index)
}
if(tempVar){
switch tempVar
{
Case 1:
SoundPlay, 1.wav, wait
tempVar:=0
Case 2:
SoundPlay, 2.wav, wait
tempVar:=0
Case 3:
SoundPlay, 3.wav, wait
tempVar:=0
Default:
}
}
}
~Numpad1::Buffer.Push(1)
~Numpad2::Buffer.Push(2)
~Numpad3::Buffer.Push(3)
我修改了@Spyre 的代码,使其更短一些。下面给出的是完整的脚本
#SingleInstance Force
;place all the wav files in same folder as this script. waves should be like 1.wav, 2.wav... wave for zero should be renamed as 99.wav
Buffer:=[]
Loop{
tempVar := Buffer[1]
if(tempVar){
SoundPlay, %tempVar%.wav, wait
tempVar:=0
Buffer.Remove(1)
}
}
~Numpad1::Buffer.Push(1)
~Numpad2::Buffer.Push(2)
~Numpad3::Buffer.Push(3)
~Numpad4::Buffer.Push(4)
~Numpad5::Buffer.Push(5)
~Numpad6::Buffer.Push(6)
~Numpad7::Buffer.Push(7)
~Numpad8::Buffer.Push(8)
~Numpad9::Buffer.Push(9)
~Numpad0::Buffer.Push(99)
;To stop playing if too many keys are pressed at once
~*Escape::
Buffer:=[]
return
当我在小键盘上按下数字时,我需要播放所按下数字的波形文件。
我使用了下面的代码
~Numpad1::SoundPlay, 1.wav, wait
return
~Numpad2::SoundPlay, 2.wav , wait
return
~Numpad3::SoundPlay, 3.wav, wait
return
当我单独按下每个数字时,它播放得很好。但是当我依次按下 123 时,我只能听到最后一波(所以当按下 123 时,我只能听到 3.wav)。我需要按顺序听到“一二三”,有什么办法吗?
If a file is playing and the current script plays a second file, the first file will be stopped so that the second one can play. On some systems, certain file types might stop playing even when an entirely separate script plays a new file.
听起来为您的热键制作单独的脚本是您可以尝试的唯一简单解决方案。
更高级的解决方案将包括更多地手动使用内部 Windows(或外部)功能来播放具有更多控制的声音。
例如。可以使用 Run command 在声音播放器中启动音频文件。我想说任何体面的声音播放器都可以从命令行参数播放声音。即使您没有看到屏幕上弹出任何声音播放器,也可能可以做到这一点。 (如果不是我想它也可以手动隐藏)
编辑:
可能理解错了问题,我的回答是同时播放多个声音。
为了解决这个问题,我使用数组作为缓冲区来捕获输入。然后,我让脚本获取数组的第一个元素,在开关中使用它来确定要播放的声音,然后删除我们正在使用的第一个元素,以便继续播放缓冲区中的下一个声音。如果我刚才说的没有多大意义,代码本身可能更容易理解。
代码如下:
#SingleInstance Force
Buffer:=[]
Loop{
Loop 1{
tempVar := Buffer[A_Index]
Buffer.Remove(A_Index)
}
if(tempVar){
switch tempVar
{
Case 1:
SoundPlay, 1.wav, wait
tempVar:=0
Case 2:
SoundPlay, 2.wav, wait
tempVar:=0
Case 3:
SoundPlay, 3.wav, wait
tempVar:=0
Default:
}
}
}
~Numpad1::Buffer.Push(1)
~Numpad2::Buffer.Push(2)
~Numpad3::Buffer.Push(3)
我修改了@Spyre 的代码,使其更短一些。下面给出的是完整的脚本
#SingleInstance Force
;place all the wav files in same folder as this script. waves should be like 1.wav, 2.wav... wave for zero should be renamed as 99.wav
Buffer:=[]
Loop{
tempVar := Buffer[1]
if(tempVar){
SoundPlay, %tempVar%.wav, wait
tempVar:=0
Buffer.Remove(1)
}
}
~Numpad1::Buffer.Push(1)
~Numpad2::Buffer.Push(2)
~Numpad3::Buffer.Push(3)
~Numpad4::Buffer.Push(4)
~Numpad5::Buffer.Push(5)
~Numpad6::Buffer.Push(6)
~Numpad7::Buffer.Push(7)
~Numpad8::Buffer.Push(8)
~Numpad9::Buffer.Push(9)
~Numpad0::Buffer.Push(99)
;To stop playing if too many keys are pressed at once
~*Escape::
Buffer:=[]
return