AutoHotKey if 语句不起作用

AutoHotKey if statement not working

这有什么问题吗?

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,并且我正在 [=18] 上进行测试=] 7 台机器,所以代码根本不应该是 运行,但是热键应该是,而 MsgBox 不是。我需要重新排序才能正常工作吗?语法对我来说是正确的,但我一直很难理解 AHKscript 的语法。

不胜感激!

这个

!f::!h

不是命令,它是一个键重映射,因此隐式包含 return。您不能在可执行上下文中使用它。有关详细信息,请参阅下面的 http://ahkscript.org/docs/misc/Remap.htm#Remarks

你不会想要在应该执行的行之间的某处有一个 return 吧。

(这主要是我的回答的副本


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

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

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