适用于Windows11 + AutoHotKey 2.x
;任务栏或桌面上滚动鼠标来切换桌面
#HotIf MouseIsOverDesktop()
WheelUp::Send "^#{Left}"
WheelDown::Send "^#{Right}"
MouseIsOverDesktop() {
MouseGetPos , , &id, &win
wincls := WinGetClass(id)
return wincls=='Shell_TrayWnd' or wincls=='WorkerW'
}
需要支持循环切换,用以下的代码
;在任务栏上滚动鼠标来切换桌面
desktop_number:=2 ;桌面数量(修改为实际)
current_desktop:=1 ;当前桌面
#HotIf MouseIsOverDesktop()
WheelUp:: PriorDesktop()
WheelDown:: NextDeskop()
MouseIsOverDesktop() {
MouseGetPos , , &id, &win
wincls := WinGetClass(id)
return wincls=='Shell_TrayWnd' or wincls=='WorkerW'
}
NextDeskop() {
global desktop_number, current_desktop
if current_desktop < desktop_number {
Send "^#{Right}"
current_desktop:=current_desktop+1
}
else {
i:=1
while i < desktop_number {
Send "^#{Left}"
i:=i+1
}
current_desktop:=1
}
sleep 100
}
PriorDesktop() {
global desktop_number, current_desktop
if current_desktop > 1 {
Send "^#{Left}"
current_desktop:=current_desktop-1
}
else {
i:=1
while i < desktop_number {
Send "^#{Right}"
i:=i+1
}
current_desktop:=desktop_number
}
sleep 100
}