autohotkey - 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
解决方案
推荐阅读
- docker - 连接到 localhost:5432 被拒绝。检查主机名和端口是否正确以及 postmaster 是否接受 TCP/IP 连接
- javascript - 如何在地图迭代中获取特定的对象键
- python - 如何使用 python-docx 搜索和替换 word 文档中的单词/文本
- java - 如何为 simpleDateFormat 创建正则表达式
- ngrx - 从效果中调用多个动作
- linux - 如何用 sed 命令替换一串特定字符
- firebase - 应用未激活时未调用 fcm onNotification
- javascript - 在 socket.io 中收集套接字返回的结果
- spring - How to use current exchange and queue name of rabbitmq with spring cloud stream rabbitmq
- python-3.x - 使用 Splinter 在网站的 textarea 中填充表格或值列表