自动热键-不同程序处于活动状态时的不同命令 [英] Autohotkey - Different commands when different programs are active

查看:77
本文介绍了自动热键-不同程序处于活动状态时的不同命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个脚本,当单击"SHIFT + ALT + I"时,它将在Microsft Word处于活动状态时发送一个特定命令,而在Microsoft PowerPoint处于活动状态时则发送另一个命令(两个程序同时运行)./p>

代码应类似于:

"if Microsoft Word is open"
+!i::
MouseMove, 300,50,0
MouseClick, left

"if Microsoft Powerpoint is open"
+!i::
MouseMove, 600,100,0
MouseClick, left

有什么(简便)的方法吗?

解决方案

是的,这很简单.

首先: 您建议的结构是可能的,但不能使用标准的热键触发器.您可以 运行一个计时器,该计时器检查窗口是否打开,然后检测按键并采取措施.或者,您确实可以使用已经链接到@user的对象. 我认为让一个热键触发一次窗口检查然后采取相应的措施更加简洁有效.

代码如下:

+!i::
IfWinActive, Microsoft Word
{
MouseMove, 300,50,0
MouseClick, left
}

IfWinActive, Microsoft Powerpoint
{
MouseMove, 600,100,0
MouseClick, left
}

Return

请注意,此函数检查窗口标题,因此在此示例中,窗口标题中的字面意义为"Microsoft Word".在此处阅读此功能: https://autohotkey.com/docs/commands/WinActive.htm

I am trying to write a script that when clicking "SHIFT+ALT+I" it sends a particular command when Microsft Word is active and another command if Microsoft PowerPoint is Active (both programs are running at the same time).

The code should be something like:

"if Microsoft Word is open"
+!i::
MouseMove, 300,50,0
MouseClick, left

"if Microsoft Powerpoint is open"
+!i::
MouseMove, 600,100,0
MouseClick, left

Is there any (easy) way of doing that?

解决方案

Yes, this is quite straightforward.

First off: The structure you propose is possible, but not with a standard hotkey trigger. You can have a timer running which checks if a window is open and that then detects keypresses and then takes action. Or you can indeed use what @user already linked to. I would consider it more neat and efficiënt to have one hotkey trigger a window check and then take action accordingly.

The code would then look like:

+!i::
IfWinActive, Microsoft Word
{
MouseMove, 300,50,0
MouseClick, left
}

IfWinActive, Microsoft Powerpoint
{
MouseMove, 600,100,0
MouseClick, left
}

Return

Do note that this function checks the window title, so there has in this example to be "Microsoft Word" literally in the window title. Read up on this function here: https://autohotkey.com/docs/commands/WinActive.htm

这篇关于自动热键-不同程序处于活动状态时的不同命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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