找回密码
 加入
搜索
查看: 2383|回复: 7

[AU3基础] 简单问题:如何判断同一个键在500ms内被按下2次?

  [复制链接]
发表于 2011-9-7 16:37:15 | 显示全部楼层 |阅读模式
用途:双击小键盘0键,启动某个事件:60为小键盘0键
$dll = DllOpen("user32.dll")
        If _IsPressed("60", $dll) Then         $mark = 1
        TrayTip("",$mark,30,1)
        DllClose($dll)
        ;Sleep(2000)
        If $mark = 1 Then
                $dll = DllOpen("user32.dll")
                $begin = TimerInit()
                Do
                        
                        If _IsPressed("60", $dll) Then
                                ;MsgBox(0, "TEST内", TimerDiff($begin)&@CRLF&_IsPressed("60", $dll))

                                TrayTip("", TimerDiff($begin) & @CRLF & _IsPressed("60", $dll), 30, 1)
                                ;DllClose($dll)
                                ;ExitLoop
                        Else
                                TrayTip("", "NO-KEY", 30, 1)
                                

                        EndIf
                        
                Until TimerDiff($begin) > 2500
上述思路居然不成,因为DO循环检测的还是第1次按下的小键盘0键。
发表于 2011-9-7 18:53:53 | 显示全部楼层
#Include <Misc.au3>
$begin = TimerInit()
$dll = DllOpen("user32.dll")
While 1
        If _IsPressed("60",$dll) Then
                If TimerDiff($begin) < 500 Then 
                        $begin = TimerInit()
                        MsgBox(0,0,"你快速按了两次0")
                Else
                        $begin = TimerInit()
                EndIf
        EndIf
        Sleep(100)
WEnd
DllClose($dll)
发表于 2011-9-7 18:54:45 | 显示全部楼层
貌似有BUG,检测为500毫秒,但延迟却100,请自测
发表于 2011-9-7 20:59:44 | 显示全部楼层
可以,不过相当麻烦,用*Performance*api 可以精确到500微秒(好象是)
发表于 2011-9-9 11:19:20 | 显示全部楼层
这个有用处 学习
发表于 2011-9-9 11:36:00 | 显示全部楼层
就是精确度问题 学习
发表于 2011-9-12 00:27:48 | 显示全部楼层
timediff自己误差就挺大的吧!
发表于 2011-9-12 18:51:58 | 显示全部楼层
本帖最后由 netegg 于 2011-9-12 18:54 编辑

楼主可以看看下面这个函数
#Include <WinAPIEx.au3>
_WinAPI_ZwDelayExecution
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-21 01:39 , Processed in 0.077192 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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