ControlSend没有发送到非最高窗口

时间:2019-03-25 12:29:07

标签: autohotkey

是否可以使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

0 个答案:

没有答案