autohotkey - 如何让 `ifWinActive` 和 `WinActivateBottom` 只使用当前桌面?
问题描述
我有一个autohotkey
脚本可以搜索特定窗口是否存在,如果存在,它将激活它。
我希望它只在当前桌面中搜索(我使用的是 Windows 10)。
你有什么建议吗?
我的脚本:
#c::
IfWinExist ,ahk_class ConsoleWindowClass
{
ifWinActive
WinActivatebottom ,ahk_class ConsoleWindowClass
else
WinActivate
return
}
解决方案
#c:: WinActivateBottomOnCurrentVirtualDesktop("ConsoleWindowClass")
WinActivateBottomOnCurrentVirtualDesktop(Class){
IfWinExist, ahk_class %Class%
{
list := ""
LastWin := ""
; get a list of those windows on the current desktop
WinGet, id, list, ahk_class %Class%
Loop, %id%
{
this_ID := id%A_Index%
If IsWindowOnCurrentVirtualDesktop(this_ID)
LastWin := this_ID ; retrieves the bottommost matching window ID
}
WinActivate, ahk_id %LastWin%
}
}
; https://autohotkey.com/boards/viewtopic.php?p=64295#p64295
; Indicates whether the provided window is on the currently active virtual desktop:
IsWindowOnCurrentVirtualDesktop(hWnd) {
onCurrentDesktop := ""
CLSID := "{aa509086-5ca9-4c25-8f95-589d3c07b48a}"
IID := "{a5cd92ff-29be-454c-8d04-d82879fb3f1b}"
IVirtualDesktopManager := ComObjCreate(CLSID, IID)
Error := DllCall(NumGet(NumGet(IVirtualDesktopManager+0), 3*A_PtrSize), "Ptr", IVirtualDesktopManager, "Ptr", hWnd, "IntP", onCurrentDesktop)
ObjRelease(IVirtualDesktopManager)
if !(Error=0)
return false, ErrorLevel := true
return onCurrentDesktop, ErrorLevel := false
}
推荐阅读
- python - Python 3.9 上的 Kivy
- react-native - 无法在 React Native 中获取布尔值和变量值
- linux - Bash: While-read loop skips the last line of comma-separated text file
- three.js - 空白白屏和 ReferenceError:未定义三个
- python - 从新闻网站上抓取新闻标题
- stripe-payments - 如何在 swapAndInvoice Laravel Cashier 的方法中传递数量?
- javascript - Sentry JS 不会忽略全局错误
- android-studio - 运行颤振医生时无法接受安卓许可证
- visual-studio - 使用 .editorconfig 抑制 xaml 中的错误
- html - 如何从使用 ajax 请求重新填充的下拉列表选项中删除 attr 'select'