【问题标题】:Layer based Keyboard using AutoHotKey: Change modifiers single press, hold, and double press behavior使用 AutoHotKey 的基于图层的键盘:更改修饰符单按、按住和双击行为
【发布时间】:2018-09-04 20:42:28
【问题描述】:

各位,

我想使用 AutoHotkey 创建一个基于图层的键盘。基本上,我想实现 shift 已经做的事情:在使用修饰符时修改每个键。

我想在以下方面改进常规班次:

  • 按下修饰符一次:只为下一个字符改变图层
  • 按住修饰符:只要修饰符关闭就改变图层
  • 按两次修饰符:进入图层模式,如大写锁定。 (以另一种方式结束)

修饰符:LAlt、RAlt、LControl、RControl(CapsLock、Shift)

我如何做到这一点?


到目前为止我在 stackoverflow 上发现的内容: 此代码允许为下一个字符按下和释放 shift

$*LShift:: 
    SendInput, {LShift Down}      ; press shift
    Input, Key, L1 M V            ; wait for input character
    If GetKeyState("LShift", "P") ; if shift still pressed, wait for release
        KeyWait, LShift
    SendInput, {LShift Up}        ; send input with shift down, the shift up
Return

此代码将双班按转换为 CapsLock

LShift::
   KeyWait, CapsLock                      ; wait to be released
   KeyWait, CapsLock, D T0.2              ; and pressed again within 0.2 seconds
   if ErrorLevel
      return
   else if (A_PriorKey = "CapsLock")
      SetCapsLockState, % GetKeyState("CapsLock","T") ? "Off" : "On"
   return

#If, GetKeyState("CapsLock", "P")         ; hotkeys go below
    a::b
#If

但我对 AHK 的经验不足,无法将其整合在一起。我的目标是拥有类似的东西

Modifier::
    ; code that makes the modifier behave like expected: single press, hold, double press
Return

#If, GetKeyState("Modifier", "P")  ; List of key remaps in specific layer
#If  

我希望这足够具体,并且您可以在这里帮助我。

谢谢!

【问题讨论】:

    标签: autohotkey


    【解决方案1】:

    将相应的布尔值(真或假)分配给变量“Double_LAlt”和“Double_LAlt_holding”,以便根据它们的值创建上下文相关的热键:

    LAlt::
        ToolTip,,,, 3
        ToolTip,,,, 4
        Double_LAlt := false
        ; Press twice or press twice and hold LAlt within 0,2 seconds
        If (A_PriorHotKey = "~LAlt Up" AND A_TimeSincePriorHotkey < 200)
        {
            Sleep, 200      
            If GetKeyState("LAlt","P")
            {               
                ToolTip,,,, 4
                ToolTip, Double_LAlt_holding,,, 2
                Double_LAlt_holding := true
            }
            else
            {   
                ToolTip,,,, 4
                ToolTip, Double_LAlt,,, 3   
                Double_LAlt := true             
            }
        }
        If !((Double_LAlt_holding) || (Double_LAlt))    ; "!" means "NOT" and "||" means "OR"
            ToolTip, LAlt_holding,,, 1
    return
    
    ~LAlt Up::
        ToolTip,,,, 1
        ToolTip,,,, 2
        Double_LAlt_holding := false
        Sleep, 100
        If (A_TimeIdlePhysical > 100)
            Tooltip, PriorHotKey = LAlt Up,,, 4
        SetTimer, RemoveTooltip, 1000
    return
    
    
    #If (Double_LAlt_holding)   ; If  this variable has the value "true"
    
        <!a:: MsgBox, a while Double_LAlt_holding       ; "<!" means "LAlt"
        <!1:: MsgBox, 1 while Double_LAlt_holding
    
    #If (Double_LAlt)
    
        a:: MsgBox, a after Double_LAlt
        1:: MsgBox, 1 after Double_LAlt
    
        ; Press a key within 2 seconds after releasing LAlt:
    #If (A_PriorHotKey = "~LAlt Up" AND A_TimeSincePriorHotkey < 2000)
    
        a:: MsgBox, a after LAlt Up
        1:: MsgBox, 1 after LAlt Up
    
    #If GetKeyState("LAlt","P")
    
        a:: MsgBox, a while LAlt_holding
        1:: MsgBox, 1 while LAlt_holding
    
    #If 
    
    RemoveTooltip:
        If (A_TimeSincePriorHotkey > 2000) ;  2 seconds
            ToolTip,,,, 4
    return
    

    【讨论】:

    • 这个方法很巧妙,谢谢。如果我没记错的话,我可以将 if 语句总结为 #If (Double_LAlt_holding) || GetKeyState(“LAlt”,“P”),对吗?我将如何完成一次 LAlt 按键以仅在下一次按键时处于活动状态?我需要摆脱 A_PriorHotKey If 语句。
    • 是的,完美运行。现在,我会试着弄清楚你到底做了什么......谢谢你:)
    猜你喜欢
    • 1970-01-01
    • 2013-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-04
    相关资源
    最近更新 更多