想要 AutoIt3 HotKeySet 模拟 AutoHotKey 应用过滤
Want AutoIt3 HotKeySet to Emulate AutoHotKey Application Filtering
Objective
我正在构建一个通用解决方案,用于使用 AutoIt3 对任意程序进行高级控制 UI,通过按各种键或发出命令来调用。
组件
- 目标UI - 通过发送点击和按键来控制的程序
- MainAu3 - AutoIt 程序执行发送
- MainIni - 包含控制位置和其他特殊符号信息的文件,还包含热键信息。所有信息都特定于特定目标 UI - 即。每个目标一个 MainIniUI
- KeyHookScript - 可选? AutoIt 或 AutoHotKey 脚本
事实
- HotKeySet() - AutoIt 函数允许设置和取消设置系统范围 热键
- AutoHotKey - 脚本语言 - 允许应用程序通过
#IfWinActive
过滤热键
- MainAu3 目前被设计为采用一些 KeyHookScript 提供的命令参数
- MainAu3 调用缓慢,由于启动时解析 MainIni,这是 necc。由于计划目标
问题
- 由于 MainAu3 的调用速度很慢,一种选择是让它 运行 在后台并有自己的键钩,或者让 KeyHookScript 以某种方式与其通信
- MainAu3 和 MainIni 将有多个实例 -- 每个 TargetUI 一个实例。如果在每个 MainAu3 中使用
HotKeySet()
,这会导致冲突,除非您每次设置和取消设置 TargetUIs 获得焦点 - 这似乎是在自找麻烦
预期方法
- 看来我需要一个 MainAu3Manager 来监视应用程序并确保正确的 MainAu3/MainIni 根据需要 运行ning。它还需要维护用 AutoHotKey
编写的 Singleton(?) KeyHookScript
问题
- 基于具有焦点且是 TargetUI 的应用程序尝试通过每个 MainAu3 换出 HotKeySet/Unset 是多么不明智?
- 鉴于这是一个糟糕的方法,哪种通信方法最适合与 运行ning MainAu3s 交谈?
- 通过
_IsPressed
在 AutoIt 中创建我自己的挂钩机制有多难,如果它在每个 MainAu3[=87] 中频繁 运行 是否会创建一个 "polling problem" =]
沟通方式
这些都是我能想到的,我希望它快速可靠,并且易于编码哈哈
- 基于文件 - 在包含命令的目录中创建文件,让 MainAu3 删除 it/them
- 注册表 - 可能比文件慢
- 隐藏 window - 通过设置 window 文本通信(我知道!)比文件快?
- 隐藏 window -
SendMessage
呃,太难编码了
- DDE - 不要让我开始
决策点
无论出于何种原因,我都需要与 运行ning MainAu3 进行通信。真正的问题是是否将keyhook机制嵌入到MainAu3实例中。
我想要的是,如果 AutoIt 有一个可靠的键钩机制,就像在 AutoHotKeys 中那样特定于应用程序 #IfWinActive
。
如果我嵌入,我讨厌设置和取消设置选项 HotKeySet()
,以及轮询 _IsPressed()
。再一次,通过 AutoHotKey 的外部键钩也很痛苦。
我想我会先尝试使用 HotKeySet()
嵌入,然后看看效果如何。
有什么建议吗?
备注
"Communication" 是单向的 - 我只需要发送命令。
如果您尝试控制的 GUI 是您自己的 GUI:
如果你想要非系统范围的热键,你应该使用
GUISetAccelerators ( accelerators [, winhandle] )
GUISetAccelerators
Sets the accelerator table to be used in a GUI window.
参数
accelerators A 2 dimensional array holding the accelerator table (See remarks).
winhandle [optional] Windows handle as returned by GUICreate() (default is the previously used window).
备注
The array passed to this function contains the hotkey and the control ID of the accelerator. The array must be defined as Local/Global $aArray[n][2] - where n is the number of accelerator keys to set:
$aArray[0][0] = Hotkey (in HotKeySet() format) of 1st accelerator
$aArray[0][1] = Control ID of the 1st accelerator, as returned by GUICtrlCreate...
$aArray[1][0] = Hotkey of 2nd accelerator
$aArray[1][1] = Control ID of the 2nd accelerator
...
$aArray[n][0] = Hotkey of nth accelerator
$aArray[n][1] = Control ID of the nth accelerator
Passing this function a non-array will unset all accelerators for the given winhandle.
示例:
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
Example()
Func Example()
GUICreate("Custom MsgBox", 225, 80)
GUICtrlCreateLabel("Please select a button.", 10, 10)
Local $idYes = GUICtrlCreateButton("Yes", 10, 50, 65, 25)
Local $idNo = GUICtrlCreateButton("No", 80, 50, 65, 25)
Local $idExit = GUICtrlCreateButton("Exit", 150, 50, 65, 25)
; Set GUIAccelerators for the button controlIDs, these being Ctrl + y and Ctrl + n
Local $aAccelKeys[2][2] = [["^y", $idYes],["^n", $idNo]]
GUISetAccelerators($aAccelKeys)
GUISetState(@SW_SHOW) ; Display the GUI.
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
MsgBox($MB_SYSTEMMODAL, "You selected", "Close")
ExitLoop
Case $idYes
MsgBox($MB_SYSTEMMODAL, "You selected", "Yes") ; Displays if the button was selected or the hotkey combination Ctrl + y was pressed.
Case $idNo
MsgBox($MB_SYSTEMMODAL, "You selected", "No") ; Displays if the button was selected or the hotkey combination Ctrl + n was pressed.
Case $idExit
MsgBox($MB_SYSTEMMODAL, "You selected", "Exit")
ExitLoop
EndSwitch
WEnd
GUIDelete() ; Delete the GUI.
EndFunc ;==>Example
如果您正在控制外部 GUI,那么可以尝试摆弄 Any GUI 使其工作
Objective
我正在构建一个通用解决方案,用于使用 AutoIt3 对任意程序进行高级控制 UI,通过按各种键或发出命令来调用。
组件
- 目标UI - 通过发送点击和按键来控制的程序
- MainAu3 - AutoIt 程序执行发送
- MainIni - 包含控制位置和其他特殊符号信息的文件,还包含热键信息。所有信息都特定于特定目标 UI - 即。每个目标一个 MainIniUI
- KeyHookScript - 可选? AutoIt 或 AutoHotKey 脚本
事实
- HotKeySet() - AutoIt 函数允许设置和取消设置系统范围 热键
- AutoHotKey - 脚本语言 - 允许应用程序通过
#IfWinActive
过滤热键
- MainAu3 目前被设计为采用一些 KeyHookScript 提供的命令参数
- MainAu3 调用缓慢,由于启动时解析 MainIni,这是 necc。由于计划目标
问题
- 由于 MainAu3 的调用速度很慢,一种选择是让它 运行 在后台并有自己的键钩,或者让 KeyHookScript 以某种方式与其通信
- MainAu3 和 MainIni 将有多个实例 -- 每个 TargetUI 一个实例。如果在每个 MainAu3 中使用
HotKeySet()
,这会导致冲突,除非您每次设置和取消设置 TargetUIs 获得焦点 - 这似乎是在自找麻烦
预期方法
- 看来我需要一个 MainAu3Manager 来监视应用程序并确保正确的 MainAu3/MainIni 根据需要 运行ning。它还需要维护用 AutoHotKey 编写的 Singleton(?) KeyHookScript
问题
- 基于具有焦点且是 TargetUI 的应用程序尝试通过每个 MainAu3 换出 HotKeySet/Unset 是多么不明智?
- 鉴于这是一个糟糕的方法,哪种通信方法最适合与 运行ning MainAu3s 交谈?
- 通过
_IsPressed
在 AutoIt 中创建我自己的挂钩机制有多难,如果它在每个 MainAu3[=87] 中频繁 运行 是否会创建一个 "polling problem" =]
沟通方式
这些都是我能想到的,我希望它快速可靠,并且易于编码哈哈
- 基于文件 - 在包含命令的目录中创建文件,让 MainAu3 删除 it/them
- 注册表 - 可能比文件慢
- 隐藏 window - 通过设置 window 文本通信(我知道!)比文件快?
- 隐藏 window -
SendMessage
呃,太难编码了 - DDE - 不要让我开始
决策点
无论出于何种原因,我都需要与 运行ning MainAu3 进行通信。真正的问题是是否将keyhook机制嵌入到MainAu3实例中。
我想要的是,如果 AutoIt 有一个可靠的键钩机制,就像在 AutoHotKeys 中那样特定于应用程序 #IfWinActive
。
如果我嵌入,我讨厌设置和取消设置选项 HotKeySet()
,以及轮询 _IsPressed()
。再一次,通过 AutoHotKey 的外部键钩也很痛苦。
我想我会先尝试使用 HotKeySet()
嵌入,然后看看效果如何。
有什么建议吗?
备注 "Communication" 是单向的 - 我只需要发送命令。
如果您尝试控制的 GUI 是您自己的 GUI:
如果你想要非系统范围的热键,你应该使用
GUISetAccelerators ( accelerators [, winhandle] )
GUISetAccelerators
Sets the accelerator table to be used in a GUI window.
参数
accelerators A 2 dimensional array holding the accelerator table (See remarks).
winhandle [optional] Windows handle as returned by GUICreate() (default is the previously used window).
备注
The array passed to this function contains the hotkey and the control ID of the accelerator. The array must be defined as Local/Global $aArray[n][2] - where n is the number of accelerator keys to set:
$aArray[0][0] = Hotkey (in HotKeySet() format) of 1st accelerator
$aArray[0][1] = Control ID of the 1st accelerator, as returned by GUICtrlCreate...
$aArray[1][0] = Hotkey of 2nd accelerator
$aArray[1][1] = Control ID of the 2nd accelerator
...
$aArray[n][0] = Hotkey of nth accelerator
$aArray[n][1] = Control ID of the nth accelerator
Passing this function a non-array will unset all accelerators for the given winhandle.
示例:
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
Example()
Func Example()
GUICreate("Custom MsgBox", 225, 80)
GUICtrlCreateLabel("Please select a button.", 10, 10)
Local $idYes = GUICtrlCreateButton("Yes", 10, 50, 65, 25)
Local $idNo = GUICtrlCreateButton("No", 80, 50, 65, 25)
Local $idExit = GUICtrlCreateButton("Exit", 150, 50, 65, 25)
; Set GUIAccelerators for the button controlIDs, these being Ctrl + y and Ctrl + n
Local $aAccelKeys[2][2] = [["^y", $idYes],["^n", $idNo]]
GUISetAccelerators($aAccelKeys)
GUISetState(@SW_SHOW) ; Display the GUI.
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
MsgBox($MB_SYSTEMMODAL, "You selected", "Close")
ExitLoop
Case $idYes
MsgBox($MB_SYSTEMMODAL, "You selected", "Yes") ; Displays if the button was selected or the hotkey combination Ctrl + y was pressed.
Case $idNo
MsgBox($MB_SYSTEMMODAL, "You selected", "No") ; Displays if the button was selected or the hotkey combination Ctrl + n was pressed.
Case $idExit
MsgBox($MB_SYSTEMMODAL, "You selected", "Exit")
ExitLoop
EndSwitch
WEnd
GUIDelete() ; Delete the GUI.
EndFunc ;==>Example
如果您正在控制外部 GUI,那么可以尝试摆弄 Any GUI 使其工作