【发布时间】:2021-06-23 15:36:45
【问题描述】:
您好,我是 autohotkey(以及一般编程)的新手,我想编写一个脚本,让我可以方便地切换到特定桌面。例如,在我的脚本 Capslock+3 切换到桌面 3。
如您所见,或者如果您尝试过,它不是很健壮。该脚本只知道一个与真实数字不同的桌面编号。例如,如果您在桌面 4 上运行脚本,则脚本仍以桌面设置为 1 开始,您必须按 Caps+4 然后按 Caps+1 才能将其设置为正确的方向。如果另一个桌面上有一个闪烁的窗口并且您单击它,它会切换到该桌面,而脚本仍然认为您在前一个桌面。
我已经搜索了 autohotkey 可以检测您在哪个桌面上的方法,但找不到任何方法。
任何人都可以提供有关如何改进它的任何提示吗?谢谢! :D
SetCapsLockState, AlwaysOff
desktop = 1
Switch(d)
{
global
;Determine how far away the desired desktop is from current one
press := (d-desktop)
desktop = %d%
;Determine which direction to switch desktops and stop script if already on current desktop
If press < 0
direction = Left
else if press > 0
direction = Right
else
return
press := Abs(press)
Loop, %press%
{
SendInput, ^#{%direction%}
Sleep, 75
}
return
}
CapsLock & 1::
Switch(1)
return
CapsLock & 2::
Switch(2)
return
CapsLock & 3::
Switch(3)
return
CapsLock & 4::
Switch(4)
return
;In case user switches desktop with traditional shortcuts
^#Left::
SendInput ^#{Left}
If desktop > 1
desktop--
return
^#Right::
SendInput ^#{Right}
If desktop < 4
desktop++
return
【问题讨论】:
-
您需要进一步澄清您的问题。您发现哪些问题被归类为不稳健?你在解决你关心的问题方面做了哪些尝试?您还可以查看此链接以改进您的问题,stackoverflow.com/help/how-to-ask
-
@JosephK。更改了标题并添加了一些说明。谢谢!
-
我使用 VirtuaWin。是的,如果您以管理员身份运行,它可以在 Windows 10 上运行。
标签: autohotkey desktop