【问题标题】:AutoHotkey - maximizing number of keyboard kombinations with limited set of keysAutoHotkey - 使用有限的键集最大化键盘组合的数量
【发布时间】:2014-10-12 17:46:52
【问题描述】:

我想设置一个 AutoHotkey 系统,使用尽可能少的键来访问许多(例如 100 个)组合键

对于初学者: Here is one good example of how to do the more basic commandAnother good method is mentioned here,我希望将两者结合起来并扩展成一个更全面的系统。

为了澄清这个问题:例如,我有 3 个键:a、b 和 c。仅从这 3 个键中获得最大使用量的好方法是什么?

为简单起见,这里有 3 个示例,说明仅使用我想到的 3 个键的方法:

  • 按住所有 3 1 秒并释放 = "MsgBox 您按下 A、B、C 1 秒并释放"
  • 同时点击全部 3 次 = "MsgBox 你点击了 A,B,C 两次"
  • 按住所有 3 3 秒并释放 = " MsgBox 你按下 A、B、C 3 秒并释放"

第二部分是如何对 AutoHotkey 进行编程以在以后添加第四个键等时避免发生冲突的风险。

我之前尝试过的一种方法是使用 keystate ,并且在大多数情况下使用双击时应该是直截了当的。这是我正在使用它的工作:

CapsLock & a:: ; a hotkey to send a message when you click a two times while 
               ; holding down CapsLock, left Shift, and left Control
GetKeyState, stateLCtrl,    LCtrl
GetKeyState, stateLShift,   LShift
    if stateLCtrl=D
        if stateLShift=D
            if (A_PriorHotkey <> "CapsLock & a" or A_TimeSincePriorHotkey > 500)
            {
                ; Too much time between presses, so this isn't a double-press.
                KeyWait, Esc
                return ; does nothing on single click 
            }
            MsgBox you clicked a two times while holding down 
                   CapsLock, left Shift, and left Control ;output of hotkey 
            return 
        else                
            Return
    else 
        return 
return 

这只是一个例子,我能想到的方法有很多。我认为这种方法不好有几个原因,所以如果有人有一个可以轻松扩展的更好的系统,那就太好了!

【问题讨论】:

    标签: keyboard-shortcuts autohotkey hotkeys


    【解决方案1】:

    我建议您查看#If context。这允许您指定所需的键状态,而无需复制大量“状态检查”代码。这是使用此上下文时您的脚本的外观。

    #If GetKeyState("Shift") and GetKeyState("Ctrl") and GetKeyState("CapsLock")
        *a:: 
            Keywait % A_ThisHotkey
            if (A_PriorHotkey = A_ThisHotkey and A_TimeSincePriorHotkey < 500)
                msgbox, short
            else
                return ; too long
        return
    #If 
    
    • 如果您的脚本中有通用热键,请使用“#If”关闭上下文

    • 热键上需要'*',因为 Ctrl 和 Shift 被视为“修饰符”

    【讨论】:

    • 啊,错过了#If,这将更有效率,并且可以扩展更多字母。由于我有“SetCapslockState, AlwaysOff”,我将使用 #If GetKeyState("Shift") 和 GetKeyState("Ctrl") CapsLock & a::
    • 如果这对您有所帮助,请随时接受这个作为答案。
    • 刚刚在我的 Windows 8 机器上测试了这个(我在它们之间同步了脚本,尽管它们处理脚本的方式略有不同(例如,我的 Windows 8 设置要求“{”在没有代码,不知道为什么会这样)),我无法让它在这个设置上工作。知道是什么原因造成的吗?
    • 我自己使用的是 Windows 8,它似乎工作得很好。你逐字复制了我的脚本并双击A 键并按下 Shift、Ctrl 和 CapsLock?
    • 是的,它在我的 Windows 7 计算机上运行良好,但在我的 Windows 8 上运行良好。不要认为有任何其他差异。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-29
    • 2019-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多