找回密码
 加入
搜索
查看: 2004|回复: 3

[系统综合] hotkeyset 同时按键会出错【已解决】

[复制链接]
发表于 2017-2-19 20:56:20 | 显示全部楼层 |阅读模式
本帖最后由 fenhanxue 于 2017-2-24 20:32 编辑

我写了个电子钢琴的软件,用数字键 1 2 3 4 5 6 7 代表音乐中的do re mi fa so la xi  的快捷键

即按下1,播放声音do
按2 播放声音re
3——mi
4——fa
5——so
6——la
7——xi

实测过程中,如果是每次只按一个键,是可以正确返回的,比如先按2再按5再按7,那么程序可以捕获到我分别按的是2 5 7,并也一次播放257

但是弹钢琴,实际弹奏中,有时候我们是需要多个键同时按下的,比如同时按下 1 2  同时按下135 等

同时按下多个键的时候,用hotkeyset 没法捕获到正确的按键,以至于无法正确播放声音文件,不知道问题何在,有没什么解决办法。

代码如下:
例如我按照节奏依次按下125,可以正常显示125

但是假如我同时按下12,则他会显示22(但是我想要得到12)
又比如我同时按下34,则他会显示33,(但是我想要得到的是34)
又比如我同时按下135,则他会显示111,(但是我想要得到的是135)

求解
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 538, 295, 192, 114)
$Edit1 = GUICtrlCreateEdit("", 16, 8, 505, 155)

$but = GUICtrlCreateButton('',8,200,40,20)
GUICtrlSetData(-1, "Edit1")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
For $i =  1 To 7
        HotKeySet($i,'tset')
Next


While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit



        EndSwitch
WEnd



Func        tset()

        GUICtrlSetData($Edit1,@HotKeyPressed,1)
        ;此处的实际代码为         SoundPlay(@HotKeyPressed&'.wav') 为了能更直观方便测试,我改为了 GUICtrlSetData

EndFunc
解决方案:目前采用的是自己2楼的笨办法
 楼主| 发表于 2017-2-19 21:06:25 | 显示全部楼层
能想到的笨办法是对每个按键都单独进行一次定义,但是这样好费时间,并且获取到的代码是跟输入的顺序刚好反过来的,不知道为什么,代码如下:


比如,按下按钮 but
发送的是几乎同时按下12345

捕获到的不是12345,而是54321
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 538, 295, 192, 114)
$Edit1 = GUICtrlCreateEdit("", 16, 8, 505, 155)

$but = GUICtrlCreateButton('',8,200,40,20)
GUICtrlSetData(-1, "Edit1")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
For $i =  1 To 7
        HotKeySet($i,'tset_'&$i)
Next


While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $but
                        Send('12345')
                        

        EndSwitch
WEnd



Func        tset_1()
        GUICtrlSetData($Edit1,1,1)
        ;此处的实际代码为         SoundPlay(@HotKeyPressed&'.wav') 为了能更直观方便测试,我改为了 GUICtrlSetData
EndFunc
Func        tset_2()
        GUICtrlSetData($Edit1,2,1)
        ;此处的实际代码为         SoundPlay(@HotKeyPressed&'.wav') 为了能更直观方便测试,我改为了 GUICtrlSetData
EndFunc
Func        tset_3()
        GUICtrlSetData($Edit1,3,1)
        ;此处的实际代码为         SoundPlay(@HotKeyPressed&'.wav') 为了能更直观方便测试,我改为了 GUICtrlSetData
EndFunc
Func        tset_4()
        GUICtrlSetData($Edit1,4,1)
        ;此处的实际代码为         SoundPlay(@HotKeyPressed&'.wav') 为了能更直观方便测试,我改为了 GUICtrlSetData
EndFunc
Func        tset_5()
        GUICtrlSetData($Edit1,5,1)
        ;此处的实际代码为         SoundPlay(@HotKeyPressed&'.wav') 为了能更直观方便测试,我改为了 GUICtrlSetData
EndFunc
Func        tset_6()
        GUICtrlSetData($Edit1,6,1)
        ;此处的实际代码为         SoundPlay(@HotKeyPressed&'.wav') 为了能更直观方便测试,我改为了 GUICtrlSetData
EndFunc
Func        tset_7()
        GUICtrlSetData($Edit1,7,1)
        ;此处的实际代码为         SoundPlay(@HotKeyPressed&'.wav') 为了能更直观方便测试,我改为了 GUICtrlSetData
EndFunc
发表于 2017-2-19 21:07:56 | 显示全部楼层
应该用函数
_IsPress
按键时,持续播放对应声音,弹起则停止播放.
发表于 2017-2-20 08:40:48 | 显示全部楼层
#include <Misc.au3>
_IsPressed ("hotkey")
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-25 16:33 , Processed in 0.078128 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表