【问题标题】:Toggle Hotkeys in Autohotkey by using a flag使用标志在 Autohotkey 中切换热键
【发布时间】:2019-06-13 21:26:51
【问题描述】:

我希望能够打开和关闭我的热键。我有像“a = f”或“d = y”这样的热键映射。我希望能够按一个键并将“a = a”切换到“a = f”并返回。现在我正在为此使用暂停键。问题是:当我想取消挂起时,我必须用鼠标手动执行此操作并右键单击取消挂起(因为我的自定义热键不再运行,所以我拥有的取消挂起的键无法识别,因为脚本被暂停)。

我的简单想法是暂停和暂停的全局热键。但我还没有找到类似的东西。

因此我制作了一个布尔标志来手动切换。为此,我不需要暂停。但只要有一个键,就可以切换标志。下面是一些示例代码:

    if (flag) 
    {   
        a::f 
    } 
    else 
    {   
        a::a 
    }

我收到重复的热键错误。

【问题讨论】:

  • 我不知道语法,但您可以尝试类似 a:: if(flag) {f} else {a}

标签: autohotkey


【解决方案1】:

切换变量的值:

flag := !flag

将根据其当前值使标志为真或假。真变假,反之亦然。

flag := false ; initialize variable

F1:: flag := !flag ; press F1 to toggle the variable's value to true/false


; The #If-directive creates context-sensitive hotkeys and hotstrings:

#If (flag) ; if this variable has the value "true"

    a::f

#If ; turn off context sensitivity

https://autohotkey.com/docs/commands/_If.htm https://autohotkey.com/docs/Variables.htm#Expressions

【讨论】:

  • 它对我来说很好用,但是有一个问题:当关闭热键同时a时,它永远不会释放它..它一直重复,因为它也会停用发布部分。有什么解决办法吗?
  • 在文件顶部添加#MaxThreadsPerHotkey 2,它允许您切换变量,以便您应该能够释放
猜你喜欢
  • 1970-01-01
  • 2019-06-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-25
  • 1970-01-01
  • 2014-08-14
  • 1970-01-01
相关资源
最近更新 更多