HotkeyHelper for ahk v2——热键设置工具类,长按、双击、单击混合

支持长按、双击、单击混合使用,简单更改后可以玩出更多花样。 目前用于Starter按键设置,可见: src/Utils/HotkeyHelper.ah2 · 如初/Starter - 码云 - 开源中国 (gitee.com) / * @N

支持长按、双击、单击混合使用,简单更改后可以玩出更多花样。

目前用于Starter按键设置,可见:src/Utils/HotkeyHelper.ah2 · 如初/Starter – 码云 – 开源中国 (gitee.com)

/**
 * @Name: HotkeyHelper
 * @Version: 0.0.1
 * @Author: ruchuby
 * @LastEditors: ruchuby
 * @LastEditTime: 2023-04-16
 * @Description: Hotkey Settings Tool Functions
 */

class HotkeyHelper {
    /**
     * @description: 
     * @param key the hotkey without modifier symbols
     * @param time The longest interval from first release to second press
     * @param CB Long press callback
     * @param block set false to add '~' for hotkey
     * @param physical set true to add '

 for hotkey
     * @return total hotkey string
     */
    static longPressHotKey(key, time, CB, block := false, physical := true) {
        totalKey := Format("{}{}{}", block ? "" : "~", physical ? "$" : "", key)
        time := String(Round(time, 1))
        handler(*) {
            if (!KeyWait(key, "T" time)) {
                CB()
                ; Endless waiting for release to avoid repeated calls
                KeyWait(key)
            }
        }
        Hotkey(totalKey, handler, "On")
        return totalKey
    }

    /**
     * @description: 
     * @param key the hotkey without modifier symbols
     * @param time The longest interval from first release to second press
     * @param doubleCB double press callback
     * @param singleCB single press callback
     * @param block set false to add '~' for hotkey
     * @param physical set true to add '

 for hotkey
     * @return total hotkey string
     */
    static doubleAndSingleHotKey(key, time, doubleCB, singleCB := (*) => 0, block := false, physical := true) {
        totalKey := Format("{}{}{}", block ? "" : "~", physical ? "$" : "", key)
        time := String(Round(time, 1))
        handler(*) {
            ; Wait for release
            if (KeyWait(key)) {
                if (KeyWait(key, "DT" time) && A_PriorKey = key) {
                    doubleCB()
                    KeyWait(key)
                } else
                    singleCB()
            }
        }
        Hotkey(totalKey, handler, "On")
        return totalKey
    }

    /**
     * @description: example of double and long press for the same key.
     * @param key the hotkey without modifier symbols
     * @param time1 Press for more than this time, it means long press
     * @param time2 The longest interval from first release to second press
     * @param longCB Long press callback
     * @param doubleCB double press callback
     * @param block set false to add '~' for hotkey
     * @param physical set true to add '

 for hotkey
     * @return total hotkey string
     */
    static doubleAndLongHotkey(key, time1, time2, longCB, doubleCB, block := false, physical := true) {
        ; Construct key string
        totalKey := Format("{}{}{}", block ? "" : "~", physical ? "$" : "", key)
        ; Round the time and convert it to string
        time1 := String(Round(time1, 1))
        time2 := String(Round(time2, 1))
        handler(*) {
            if (KeyWait(key, "T" time1)) {
                ; Released within time1, waiting for the second press
                if (KeyWait(key, "DT" time2)  && A_PriorKey = key) {
                    ; Second Press within time2
                    doubleCB()
                    ; Endless waiting for release to avoid repeated calls
                    KeyWait(key)
                    ; if you like, you can add 'KeyWait(key, "DT" time2)' for triple key, uadruple key...
                }
            } else {
                ; Press over the time1
                longCB()
                ; Endless waiting for release to avoid repeated calls
                KeyWait(key)
                ; Finally, the long press released.
            }
        }
        Hotkey(totalKey, handler, "On")
        return totalKey
    }
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA捐赠
共{{data.count}}人
人已捐赠
函数

金额中文阿拉伯数字互转函数

2023-2-6 10:13:21

函数造物硬件

【lib】COM串口库

2023-9-4 9:24:50

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