【问题标题】:Autohotkey - Send Left control on long press otherwise send EnterAutohotkey - 长按发送左控制,否则发送 Enter
【发布时间】:2017-08-30 11:28:35
【问题描述】:

这是我的脚本。 Capslock 映射为长按发送左控制,否则发送转义。这按预期工作。

SetCapsLockState, alwaysoff
Capslock::
    Send {LControl Down}
    KeyWait, CapsLock
    Send {LControl Up}
    if ( A_PriorKey = "CapsLock" ){
        Send {Esc}
    }
    return

; Send left control when long pressed, otherwise behave a normal enter key
Enter::                
    send {LControl Down}
    KeyWait, Enter, T5
    Send {LControl Up} 
    if ( A_PriorKey = "Enter" ){
        Send {Enter}
    }
    return

但是Enter键没有等待长按,它很快就超时了。这不是我的期望。它的行为应该像上面的 sn-p

【问题讨论】:

  • 您预计Enter 键的超时时间是多久?您为后者定义了 5 秒超时,但没有为前者定义。
  • 我的期望是,它不应该像 Capslock 绑定那样超时。我尝试了 5 秒,但没有帮助。

标签: autohotkey


【解决方案1】:

如果我对问题的理解正确,这应该可以满足您的要求:

Enter:: 
SendInput, {LCtrl Down}
Sleep, 100
KeyWait, Enter
SendInput, {LCtrl Up}
if ( A_PriorKey = "Enter" ){
    Send {Enter}
}
return

另外,我假设您在最后通过单个 Enter 按键进行了捕获。如果不是这种情况,并且您希望通过所有这些(同时按住 Enter 键),以下将完成。

~Enter:: 
SendInput, {LCtrl Down}
Sleep, 100
KeyWait, Enter
SendInput, {LCtrl Up}
return

【讨论】:

  • 知道为什么这对字母键不起作用吗?我尝试使用键 f,但与 Enter 不同的是,f 永远不会在快速释放时发送。
  • 它通过添加$ 来工作,即使用$f:: 作为热键。出于某种原因,Enter 似乎不需要它。
  • @tejasvi88 在使用SendInput 进行字母数字输出时,我会参考{RAW} 修饰符。请参阅此处的示例 #4:autohotkey.com/docs/commands/Send.htm#ExSendInputRaw
猜你喜欢
  • 1970-01-01
  • 2023-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-08
  • 1970-01-01
  • 2016-12-01
  • 2016-04-18
相关资源
最近更新 更多