Autohotkey 希望AutoIt3热键集模拟自动热键应用程序筛选

Autohotkey 希望AutoIt3热键集模拟自动热键应用程序筛选,autohotkey,autoit,Autohotkey,Autoit,目标 我正在构建一个通用解决方案,用于使用AutoIt3对任意程序UI进行高级控制,通过按各种键或发出命令来调用 组件 TargetUI-通过发送点击和按键来控制的程序 MainAu3-执行发送的AutoIt程序 MainIni-包含控制位置和其他特殊符号信息的文件,也包含热键信息。所有信息都特定于特定的TargetUI,即每个TargetUI都有一个MainIni KeyHookScript-可选?AutoIt或AutoHotKey脚本 事实 热键集()-自动IT功能允许设置和取消设置系

目标

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

组件

  • TargetUI-通过发送点击和按键来控制的程序
  • MainAu3-执行发送的AutoIt程序
  • MainIni-包含控制位置和其他特殊符号信息的文件,也包含热键信息。所有信息都特定于特定的TargetUI,即每个TargetUI都有一个MainIni
  • KeyHookScript-可选?AutoIt或AutoHotKey脚本
事实

  • 热键集()-自动IT功能允许设置和取消设置系统范围的热键
  • 自动热键-脚本语言-允许应用程序通过
    #IfWinActive
  • MainAu3目前被设计为接受某个KeyHookScript提供的命令param
  • 由于在启动时解析MainIni(即necc),MainAu3的调用速度很慢。由于项目目标
问题

  • 由于MainAu3调用速度较慢,一种选择是让它在后台运行并拥有自己的keyhook,或者让KeyHookScript以某种方式与之通信
  • MainAu3和MainIni将有多个实例——每个TargetUI都有一个实例。如果在每个MainAu3中使用
    HotKeySet()
    ,这会导致冲突,除非每次targetui获得焦点时都设置并取消设置,这似乎是自找麻烦
预期方法

  • 看起来我需要一个MainAu3管理器来监控应用程序并确保正确的MainAu3/MainIni在需要时运行。它还需要维护用AutoHotKey编写的Singleton(?)KeyHookScript
问题

  • 基于具有焦点且是TargetUI的应用程序,尝试通过每个MainAu3交换热键集/取消设置有多不明智
  • 鉴于这是一种糟糕的方法,与运行中的Mainau3对话的最佳通信方法是什么
  • 通过
    \u IsPressed
    在AutoIt中创建我自己的挂钩机制有多困难?如果它在每个MainAu3中频繁运行,会不会产生“轮询问题”
沟通方法

这些都是我能想到的,我希望这是快速和可靠的,容易编码哈哈

  • 基于文件-在包含命令的某个目录中创建一个或多个文件,让MainAu3删除它/它们
  • 注册表-可能比文件慢
  • 隐藏窗口-通过设置窗口文本(我知道!)比文件更快进行通信
  • 隐藏窗口-
    SendMessage
    ugh,太难编码
  • DDE-不要让我开始
决策点

我将需要与运行中的MainAu3进行沟通,无论原因如何。真正的问题是是否在MainAu3实例中嵌入keyhook机制

我想要的是,AutoIt是否有一个可靠的键钩机制,该机制与AutoHotKeys
#IfWinActive
中的键钩一样,是特定于应用程序的

如果我嵌入,我讨厌设置和取消设置
热键集()
,以及轮询
\u IsPressed()
。同样,通过自动热键的外部钥匙钩也是一种痛苦

我想我会先尝试嵌入
HotKeySet()
,看看效果如何

有什么建议吗

注意
“通信”是单向的-我只需要发送命令。

如果您试图控制的GUI是您自己的GUI:

如果您想要非系统范围的热键,应该使用

GUISetAccelerators(accelerators[,winhandle])

参数

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
#包括
#包括
示例()
Func示例()
GUI创建(“自定义MsgBox”,225,80)
GUICtrlCreateLabel(“请选择一个按钮。”、10、10)
本地$idies=GUICtrlCreateButton(“是”,10,50,65,25)
本地$idNo=GUICtrlCreateButton(“否”、80、50、65、25)
本地$idExit=GUICtrlCreateButton(“退出”,150,50,65,25)
; 为按钮控件ID设置GUI加速器,它们是Ctrl+y和Ctrl+n
本地$aAccelKeys[2][2]=[[“^y”、$idies]、“^n”、$idNo]]
GUISetAccelerators($aAccelKeys)
GuiseState(@SW_SHOW);显示GUI。
而1
开关GUIGetMsg()
案例$GUI\u事件\u结束
MsgBox($MB_SYSTEMMODAL,“您选择的”,“关闭”)
ExitLoop
案例$IDYS
MsgBox($MB_SYSTEMMODAL,“您选择了”,“是”);显示是选择了按钮还是按了热键组合Ctrl+y。
案件$idNo
MsgBox($MB_SYSTEMMODAL,“您选择了”、“否”);显示是选择了按钮还是按了热键组合Ctrl+n。
案例$idExit
MsgBox($MB_SYSTEMMODAL,“您选择的”,“退出”)
ExitLoop
终端开关
温德
guidelet();删除GUI。
EndFunc;==>例子

如果您正在控制一个外部GUI,那么可以尝试摆弄它,使其正常工作

一次问一个问题怎么样?\u表示不可靠。
#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