If Then 在 AutoHotkey 中循环以在桌面之间切换

If Then Loop in AutoHotkey to switch between desktops

假设 ^RButton 切换到我的右侧桌面,^LButton 切换到我的左侧桌面。接下来的问题是,每当我切换到正确的桌面时,都会打开一个下拉菜单,因为我使用鼠标右键作为热键。为了解决这个问题,我可以添加 sleep 500 然后发送 {Escape} 退出下拉菜单。到目前为止,一切都很好。 但是,如果我现在想从桌面 1 切换到桌面 5,我不能连续执行 5 个 ^RButtons,而是必须在每次单击之间等待半秒。真烦人! 对于如何避免每次点击之间等待 500 毫秒的任何想法,我将不胜感激? 我的想法是使用 if 语句。虽然我不知道如何编程... 它看起来像这样:

If ^RButton = True, go to right desktop, 
if after 500 miliseconds there were no further ^RButton clicks, 
then send, {Escape}. 
If there were ^RButton clicks, 
go to the right desktop and wait 500 miliseconds for another ^RButton click,
then send, {Escape}.

如果有人能将我的文本代码转换成 AutoHotkey 代码就太棒了:D

试试这个

^RButton:: SendEvent {LWin down}{LCtrl down}{Right down}{LWin up}{LCtrl up}{Right up} ; switch to next virtual desktop
^LButton:: SendEvent {LWin down}{LCtrl down}{Left down}{LWin up}{LCtrl up}{Left up}   ; switch to previous virtual desktop

编辑:

作为 stand-alone 脚本适合我。

也试试

^RButton:: 
    Send {LWin down}{Ctrl down}{Right}{LWin up}{Ctrl up}    ; switch to next virtual desktop
    SetTimer, CloseContextMenu, -50
return

^LButton:: Send {LWin down}{Ctrl down}{Left}{LWin up}{Ctrl up}  ; switch to previous virtual desktop

CloseContextMenu:
    KeyWait, Ctrl, L
    ; Sleep, 300
    Send {Esc}
return

https://www.autohotkey.com/docs/commands/SetTimer.htm