修饰键的 的单击、双击、甚至多击以及长按 执行不同功能写法[以 ctrl键 举例]

注:修饰键就是 ctrl shift alt 等这些键。

ahkv1的写法。

经过群里多个回合的激烈讨论,解决了很多极端误触发的情况。

无数次修改后,得到目前比较完美的写法

该写法不会影响到ctrl与其他键组合的正常使用。

 

举例:

左ctrl的单击、双击、长按执行不同功能【按住超过200ms 算长按】

~LCtrl::
    StartTime := A_TickCount
    KeyWait LControl
    if (A_TickCount - StartTime > 200 and A_PriorKey = "LControl"){
        MsgBox 长按执行
        return
    }
    KeyWait, LControl, D T0.2
    If (A_PriorKey = "LControl"){		
        if (ErrorLevel=1){
            MsgBox 单击 
        }else{
            KeyWait LControl
            KeyWait, LControl, D T0.2
            if (A_PriorKey ="LControl"){
                if (ErrorLevel=1){
                    MsgBox 双击 
                }
            }
        }
    }

无限延伸举例:

左ctrl的单击、双击、三连击、长按执行不同功能【按住超过200ms 算长按】

~LCtrl::
    StartTime := A_TickCount
    KeyWait LControl
    if (A_TickCount - StartTime > 200 and A_PriorKey = "LControl"){
        MsgBox 长按执行
        return
    }
    KeyWait, LControl, D T0.2
    If (A_PriorKey = "LControl"){		
        if (ErrorLevel=1){
            MsgBox 单击 
        }else{
            KeyWait LControl
            KeyWait, LControl, D T0.2
            if (A_PriorKey ="LControl"){
                if (ErrorLevel=1){
                    MsgBox 双击 
                }else{
                    KeyWait LControl
                    if (A_PriorKey ="LControl"){
                        MsgBox 三连击
                    }
                }
            }
        }
    }

实际应用举例:

单击左ctrl复制,双击左ctrl粘贴,长按不执行任何操作

~LCtrl::
    StartTime := A_TickCount
    KeyWait LControl
    if (A_TickCount - StartTime > 200 and A_PriorKey = "LControl"){
        return
    }
    KeyWait, LControl, D T0.2
    If (A_PriorKey = "LControl"){		
        if (ErrorLevel=1){
            send, ^c 
        }else{
            KeyWait LControl
            KeyWait, LControl, D T0.2
            if (A_PriorKey ="LControl"){
                if (ErrorLevel=1){
                    send, ^v
                }
            }
        }
    }

 

 

给TA捐赠
共{{data.count}}人
人已捐赠
应用案例

自动复制的实现与逻辑分析

2024-1-11 13:37:18

应用

使用AutoHotkey创建高亮鼠标下控件的实用工具

2024-2-19 14:36:30

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
有新私信 私信列表
搜索