如果然后在AutoHotkey中循环以在桌面之间切换

时间:2019-06-30 07:57:17

标签: loops if-statement autohotkey wait

比方说,^ RButton切换到我的右桌面,^ LButton切换到我的左桌面。然后的问题是,每当我切换到右侧桌面时,都会打开一个下拉菜单,因为我将鼠标右键用作热键。为了解决这个问题,我可以添加sleep 500,然后发送{Escape}退出下拉菜单。到目前为止,一切都很好。 但是,如果我现在想从台式机1切换到台式机5,我不能只连续执行5个^ RButton,而必须在每次单击之间等待半秒。真烦人! 对于您如何避免每次点击之间等待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

1 个答案:

答案 0 :(得分:2)

尝试一下

^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

编辑:

作为一个独立脚本适用于我。

也尝试

^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