使用AutoHotKey的基于图层的键盘:更改修改器单击,按住和双按行为

时间:2018-03-26 16:09:30

标签: autohotkey

人,

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

我希望改善以下常规转变:

  • 按一次修改器:仅更改下一个字符的图层
  • 只要修改器已关闭,
  • 保持修饰符更改图层
  • 按两次修改器:进入图层模式,如capslock。 (由另一家媒体报道)

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

我是如何实现这一目标的?

到目前为止我在stackoverflow上发现了什么: 此代码允许为下一个字符按下和释放移位

$*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  

我希望这很具体,你可以帮助我。

谢谢!

1 个答案:

答案 0 :(得分:0)

将相应的Booleam值(true或false)分配给变量" 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