目标
我正在构建一个通用解决方案,用于使用AutoIt3高级控制任意程序UI,通过按下各种键或发出命令来调用。
零件
事实
#IfWinActive
问题
HotKeySet()
,这会导致冲突,除非每次TargetUIs获得焦点时设置和取消设置 - 这似乎是在寻找麻烦预期方法
问题
_IsPressed
在AutoIt中创建自己的挂钩机制有多难,这会产生一个"轮询问题"如果它在每个MainAu3中频繁运行沟通方法
这些都是我能想到的,我希望它快速可靠,并且很容易编码哈哈
SendMessage
呃,太难编码决策点
我需要与正在运行的MainAu3进行通信,因为原因。真正的问题是是否将关键钩机制嵌入到MainAu3实例中。
我想要的是AutoIt是否有一个可靠的机制,用于特定于应用程序的关键钩,如AutoHotKeys #IfWinActive
。
如果我嵌入,我讨厌设置和取消设置HotKeySet()
的选项,以及轮询_IsPressed()
。然后,通过AutoHotKey的外部键钩也很痛苦。
我想我会首先尝试使用HotKeySet()
进行嵌入,然后看看它是如何起作用的。
有什么建议吗?
注意 "通信及#34;是单向的 - 我只需要发送命令。
答案 0 :(得分:1)
如果您尝试控制的GUI是您自己的GUI:
如果您想要非系统范围的热键,则应使用
GUISetAccelerators(加速器[,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以使其正常工作