【问题标题】:Autohotkey. How to make work both `a hotkey` and `a hotkey+key`?自动热键。如何同时使用“热键”和“热键+键”?
【发布时间】:2015-09-13 18:48:44
【问题描述】:

我想在我的脚本中有两个热键。即LWin UpLWin+LAlt Up。我试过这样做:

LAlt & LWin Up:: ;I've also tried commenting out the first
LWin & LAlt Up:: ;or the second line
LWin Up::
  msgbox, % A_ThisHotkey
return

但是输出取决于按键被按下和释放的顺序。释放第一个键和第二个键之间的时间也会影响结果。有时我得到两个 MessageBox,有时只有一个,有时甚至根本没有(第一行被注释掉,按 alt,按 win,release win,release alt)。我如何使它工作?明确一点:我只想得到一个 MessageBox。

在答案中,很高兴看到一个脚本提供有关按下的热键的完整信息以及按下和释放它所包含的键的顺序。 *释放a hotkey+key组合后只能触发一个热键。

【问题讨论】:

    标签: autohotkey


    【解决方案1】:

    你不能把它们放在一起。
    你应该使用这样的东西:

    altPressed := false
    
    LAlt & LWin Up::
        msgbox, % A_ThisHotkey
    return
    
    LWin & LAlt Up::
        msgbox, % A_ThisHotkey
        altPressed := true
    return
    
    LWin Up::
        if !altPressed {
            msgbox, % A_ThisHotkey
        }
        altPressed := false
    return
    

    如果你想要做的而不是msgbox 在我的代码中过于分散,你可以使用下面的:

    SetTimer, toDo, 10
    
    toDo:
        if doWhatEver {
            ;; HERE DESCRIBE WHAT TO DO
            doWhatEver := false
        }
    return
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    altPressed := false
    doWhatEver := false
    
    LAlt & LWin Up::
        doWhatEver := true
    return
    
    LWin & LAlt Up::
        doWhatEver := true
        altPressed := true
    return
    
    LWin Up::
        if !altPressed {
            doWhatEver := true
        }
        altPressed := false
    return
    

    【讨论】:

    • 它不起作用,但我明白了。谢谢你的回答。
    • @user2277240 它有效。有一个小问题,当您按下 alt + Win 时,因为您首先释放 Win 然后释放 alt 它调用 altPressed := true 导致 Lwin Up 在第一次按下时不运行。第二次按下它就可以了(我的意思是单独的 LWin 键)。
    【解决方案2】:

    TechJS 的回答并没有像我希望的那样工作,所以这是我的脚本。它检测按键的按下和释放顺序,不依赖于按键按下/释放之间的时间。

    global firstPressed := ""
    
    LAlt::
      altDown := true
      if (winDown)
        return
      firstPressed := "!"
    return
    
    LWin::
      winDown := true
      if (altDown)
        return
      firstPressed := "#"
    return
    
    LAlt Up::
      altDown := false
      if (!winDown) {
        if (comboJustUp) {
          comboJustUp := false
          return
        }
        msgbox !
      }
      if (winDown) {
        comboJustUp := true
        if (firstPressed = "#") 
          msgbox #!!.
        if (firstPressed = "!")
          msgbox !#!.
      }
    return
    
    LWin Up::
      winDown := false
      if (!altDown) {
        if (comboJustUp) {
          comboJustUp := false
          return
        }
        msgbox #
      }
      if (altDown) {
        comboJustUp := true
        if (firstPressed = "!") ; \here is one bug though. If you switch theese
          msgbox !##.           ; /two lines
        if (firstPressed = "#") ; \with theese
          msgbox #!#.           ; /two. It won't work correctly for some reason
      }
    return
    

    【讨论】:

      猜你喜欢
      • 2012-11-16
      • 2018-07-07
      • 1970-01-01
      • 2013-03-20
      • 1970-01-01
      • 1970-01-01
      • 2021-12-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多