double click / double press on the key for different commands Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
monatilda23
Posts: 26
Joined: 25 Jan 2022, 10:24

double click / double press on the key for different commands

Post by monatilda23 » 28 Jan 2022, 14:18

greetings everyone, can you please share any ideas on how to compose the script for this task:
___

given: standard W10 hotkey for switching VirtualDesktops

1) [Ctrl + WIN + right arrow] : move to next desktop

2) [Ctrl + WIN + left arrow] : move to previous desktop
___

what I want to do is not just re-map it to another key, but make it more elegant
Im looking for these options

1) to double-click [RShift] (similar like typical mouse double-click to open smth) for [Ctrl + WIN + right arrow]
2) and then to double-click again the same [RShift] for the opposite command [Ctrl + WIN + left arrow]

in simple words, when I need to move to next desktop - I double-click RSHift
When I need to go to the previous desktop - I double-click RShift again

is that even possible?
thanks

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: double click / double press on the key for different commands

Post by amateur+ » 28 Jan 2022, 14:45

Didn't test it since I don't have virtual desktops.

Code: Select all

~RShift Up::
ToggleVirtualDesktops() {
	static toggle := 0
	KeyWait RShift, D T0.3
	if !ErrorLevel
		send % "^#{" . ((toggle := !toggle) ? "Right" : "Left") . "}"
}
Last edited by amateur+ on 28 Jan 2022, 14:48, edited 1 time in total.
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

User avatar
mikeyww
Posts: 27056
Joined: 09 Sep 2014, 18:38

Re: double click / double press on the key for different commands  Topic is solved

Post by mikeyww » 28 Jan 2022, 14:48

Another one:

Code: Select all

~RShift Up::Send % A_ThisHotkey != A_PriorHotkey || A_TimeSincePriorHotkey > 400
             ? "" : "#^" ((right := !right) ? "{Right}" : "{Left}")

monatilda23
Posts: 26
Joined: 25 Jan 2022, 10:24

Re: double click / double press on the key for different commands

Post by monatilda23 » 28 Jan 2022, 14:57

greetings @amateur+ , thanks for your reply. Ve just tested the script, it does the job, but the new problem occurs - when switching to the next VirtualDesktop, the Start Menu opens up on that Desktop to I switched.

monatilda23
Posts: 26
Joined: 25 Jan 2022, 10:24

Re: double click / double press on the key for different commands

Post by monatilda23 » 28 Jan 2022, 15:01

hi there @mikeyww , thank your for the reply. Your code works brilliantly! I tested it also for an issue that RShift not kept pressed when typing then, but it seems fine!
Much obliged

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: double click / double press on the key for different commands

Post by amateur+ » 28 Jan 2022, 15:10

@mikeyww, seems like our solutions have one bug: they fail if the user quickly types something that contains another button between RShifts. For example RShift+D+RShift+R or quickly switches keyboard layout twice like RShift+AltRShift+Alt or RShift+CtrlRShift+Ctrl.
So we have to use Input to avoid this:

Code: Select all

~RShift::
ToggleVirtualDesktops() {
	static toggle := 0
	Input, key, L1 T0.4 V, {RShift}{LControl}{RControl}{LAlt}{RAlt}{LShift}{LWin}{RWin}{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{CapsLock}{NumLock}{PrintScreen}{Pause}
	if (ErrorLevel = "EndKey:RShift")
		Send, % "^#{" . ((toggle := !toggle) ? "Right" : "Left") . "}"
}
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

monatilda23
Posts: 26
Joined: 25 Jan 2022, 10:24

Re: double click / double press on the key for different commands

Post by monatilda23 » 28 Jan 2022, 15:26

hey @amateur+thank your for your contributing. Ive tried the latest script from you, maybe something wrong with W10 versions compatibility, IKD, Im running W10 ver 2004, and I haven't found the mistake you mention but still have the problem with Start Menu appears when toggling to next VirtualDesktop by pressing the RShift

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: double click / double press on the key for different commands

Post by amateur+ » 28 Jan 2022, 15:36

You can try these variants:

Code: Select all

~RShift::
ToggleVirtualDesktops() {
	static toggle := 0
	Input, key, L1 T0.3 V, {RShift}{LControl}{RControl}{LAlt}{RAlt}{LShift}{LWin}{RWin}{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{CapsLock}{NumLock}{PrintScreen}{Pause}
	if (ErrorLevel = "EndKey:RShift")
		Send, % "{Blind}{RShift Up}#^{" . ((toggle := !toggle) ? "Right" : "Left") . "}"
}
or this:

Code: Select all

~RShift::
ToggleVirtualDesktops() {
	static toggle := 0
	Input, key, L1 T0.3 V, {RShift}{LControl}{RControl}{LAlt}{RAlt}{LShift}{LWin}{RWin}{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{CapsLock}{NumLock}{PrintScreen}{Pause}
	if (ErrorLevel = "EndKey:RShift")
		Send, % "{Blind}{RShift Up}{RWin Down}{RCtrl Down}{" . ((toggle := !toggle) ? "Right" : "Left") . "}{RCtrl Up}{vkFF}{RWin Up}"
}
As for that bug, just press quickly as you can RShift+M release both RShift. Has it switched you to another virtual desktop?
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: double click / double press on the key for different commands

Post by amateur+ » 30 Jan 2022, 19:23

monatilda23 wrote:
28 Jan 2022, 15:26
but still have the problem with Start Menu appears when toggling to next VirtualDesktop by pressing the RShift
I've tested it right now with virtual desktops and both my scripts from the previous message don't reproduce your problem with Start Menu. Do you still have it?
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

monatilda23
Posts: 26
Joined: 25 Jan 2022, 10:24

Re: double click / double press on the key for different commands

Post by monatilda23 » 31 Jan 2022, 16:24

hi there, if you dont mind I would test it tomorrow, as at the moment I have unstable system because I was testing millions of software and my PC lags so much. When I restore the PC I ll write you back if the problem persists, thanks
amateur+ wrote:
30 Jan 2022, 19:23
monatilda23 wrote:
28 Jan 2022, 15:26
but still have the problem with Start Menu appears when toggling to next VirtualDesktop by pressing the RShift
I've tested it right now with virtual desktops and both my scripts from the previous message don't reproduce your problem with Start Menu. Do you still have it?

Post Reply

Return to “Ask for Help (v1)”