【问题标题】:AutoHotKey if statement not workingAutoHotKey if 语句不起作用
【发布时间】:2015-11-03 21:03:11
【问题描述】:

这有什么问题?

if A_OSVersion = WIN_7 or A_OSVersion = WIN_XP
   {
   MsgBox, Win7 or XP
} else {
   if WinActive("ahk_exe Explorer") {
   !f::!h
   }
}

目标是当我运行 Windows 8、8.1 或 10 时,在资源管理器中用 Alt+H 替换 Alt+F,并且我正在 Windows 7 机器上进行测试,因此代码根本不应该运行,但是热键可以,MsgBox 不会。我需要重新排序才能让它工作吗?语法对我来说是正确的,但我一直很难使用 AHKscript 的语法。

感谢善良的cmets!

【问题讨论】:

    标签: if-statement syntax autohotkey


    【解决方案1】:

    这个

    !f::!h
    

    不是命令,它是键重映射,因此隐含包含return。您不能在可执行上下文中使用它。详情请见下方http://ahkscript.org/docs/misc/Remap.htm#Remarks

    你不希望在应该执行的行之间有一个 return,对吧。

    (这主要是我的答案here的副本)


    对于context-sensitive 热键,使用预处理器指令:

    #if (A_OSVersion = "WIN_7" or A_OSVersion = "WIN_XP") and not winActive("ahk_exe Explorer")
       !f::!h
    #if
    

    【讨论】:

    • 甜蜜!我需要做的就是将not 放在if 的另一部分并将Explorer 更改为Explorer.exe,它就像Linux 一样工作。谢谢!
    【解决方案2】:
    #if winActive("ahk_exe Explorer") and !(A_OSVersion = "WIN_7" or A_OSVersion = "WIN_XP")
      !f::!h
    #if
    

    要在正常的脚本流程中执行此操作,您需要使用热键命令,但它不会是重新映射,而是发送另一组键的热键...

    【讨论】:

      猜你喜欢
      • 2012-07-16
      • 2021-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 2017-10-22
      • 2018-05-11
      • 2015-05-05
      相关资源
      最近更新 更多