首页 > 解决方案 > ControlSend 不发送到非最顶层窗口

问题描述

是否可以使 ControlSend 发送/单击到背景窗口?此代码通过 id / 处理程序查找窗口,但仅当窗口位于最顶层时才发送单击 / 击键。如果窗口不在最顶层,ControlSend 会跳过它的动作。ControlClick 强制将窗口置于顶部,然后单击。

#Singleinstance
DetectHiddenWindows, On
#SingleInstance Force
#MaxThreadsPerHotkey, 2
SendMode Input  ; Recommended for new scripts


SetControlDelay -1


PostClick(x,y,win="A") {
    lParam := x & 0xFFFF | (y & 0xFFFF) << 16
    PostMessage, 0x201, , %lParam%, , %win% ;WM_LBUTTONDOWN 
    PostMessage, 0x202, , %lParam%, ,  %win% ;WM_LBUTTONUP 
}


RunAsAdmin() {
    Loop, %0% {
        param := %A_Index%  ; Fetch the contents of the variable whose name is contained in A_Index.
        params .= A_Space . param
    }
    ShellExecute := A_IsUnicode ? "shell32\ShellExecute":"shell32\ShellExecuteA"
    if not A_IsAdmin
    {
        If A_IsCompiled
            DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_ScriptFullPath, str, params , str, A_WorkingDir, int, 1)
        Else
            DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_AhkPath, str, """" . A_ScriptFullPath . """" . A_Space . params, str, A_WorkingDir, int, 1)
        ExitApp
    }
}

RunAsAdmin()

F1::
    Loop
    {
    ; http://particle-clicker.web.cern.ch/particle-clicker/
    WinGet, WinID, ID, Particle Clicker - Google Chrome

    ; Send keystrokes only if tab active and topmost, suspend if focus lost, continue when gain focue
    ; ControlSend, ahk_parent, {Space}, ahk_id %WinID%   

    ; send clicks only if tab not mininised, if tab on background - force bring it to front
    ; ControlClick, x799 y449, ahk_id %WinID%

    ; same as above
    ; ControlClick, x799 y449, ahk_id %WinID%,,,,NA

    ; same as above
    ; Controlclick x799 y449,ahk_id %WinID%,,Left,1,NA

    ; same as above
    PostClick(799,449,"Particle Clicker - Google Chrome")


    sleep 1000
} 
return

F12::ExitApp

标签: autohotkey

解决方案


推荐阅读