AutoHotKey,如果语句不起作用 [英] AutoHotKey if statement not working

查看:258
本文介绍了AutoHotKey,如果语句不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这有什么问题?

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,并且正在Windows 7计算机上进行测试时,用Explorer中的Alt + H替换Alt + F,因此该代码根本不应运行,但是热键可以,而MsgBox不能.我需要重新排序才能使其正常工作吗?语法对我来说似乎很正确,但是我一直很难使用AHKscript的语法.

The goal is to replace Alt+F with Alt+H in Explorer when I'm running Windows 8, 8.1, or 10, and I am testing on a Windows 7 machine, so the code shouldn't run at all, but the hotkey does and the MsgBox doesn't. Do I need to reorder things for it to work? The syntax looks right to me, but I've been having a hard time with syntax for AHKscript.

感谢您的评论!

推荐答案

!f::!h

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

isn't a command, it's a key remap and thus, implicitly contains a return. You cannot use it within executable context. For details, see http://ahkscript.org/docs/misc/Remap.htm#Remarks somewhere below.

您不想在应该执行的行之间的某个地方得到回报.

You wouldn't wanna have a return somewhere in between the lines which should be executed, would you.

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

(this was mostly a copy of my answer here)

对于上下文敏感热键,请使用预处理器指令:

For context-sensitive hotkeys, use the preprocessor directives:

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

这篇关于AutoHotKey,如果语句不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆