想要 AutoIt3 HotKeySet 模拟 AutoHotKey 应用过滤

Want AutoIt3 HotKeySet to Emulate AutoHotKey Application Filtering

Objective

我正在构建一个通用解决方案,用于使用 AutoIt3 对任意程序进行高级控制 UI,通过按各种键或发出命令来调用。

组件

事实

问题

预期方法

问题

沟通方式

这些都是我能想到的,我希望它快速可靠,并且易于编码哈哈

决策点

无论出于何种原因,我都需要与 运行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 使其工作