How to avoid loops with Volume up an down Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Kamil KW
Posts: 7
Joined: 21 Nov 2017, 11:31

How to avoid loops with Volume up an down

21 Nov 2017, 11:49

Hi,

How do I prevent that loop? I have this script that uses [ and ] keys to control volume, but I can't get the [ and ] characters now. How do I get to type them now? I tried appending the code with +, ! and CTRL symbol and nothing works.

This is my script that works nicely to control volume:

Code: Select all


]::
Send {Volume_Up}
Return

[::
Send {Volume_Down}
Return

Adding this and similar before or after does not help to type [ and ] characters :

Code: Select all


+::
Send ]
Return

+[::
Send [
Return

There are no errors or anything - I just can't type those characters anymore.

Many thanks in advance.
Kamil
Kamil KW
Posts: 7
Joined: 21 Nov 2017, 11:31

Re: How to avoid loops with Volume up an down

21 Nov 2017, 18:36

Thanks. We have some progress, but not there yet - when I press shift and a bracket, I get now { or }, but still no square brackets. Any idea?
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: How to avoid loops with Volume up an down

21 Nov 2017, 18:49

You need to put tildes in front:

~]::Volume_Up
~[::Volume_Down
Kamil KW
Posts: 7
Joined: 21 Nov 2017, 11:31

Re: How to avoid loops with Volume up an down

21 Nov 2017, 19:44

That's not ideal either as now it does two things at the same time: it turns the volume up (or down) and types the character (either [ or { with Shift).

Any other ideas?
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: How to avoid loops with Volume up an down

21 Nov 2017, 20:42

What would be ideal? You can't expect the script to know when you want to change the volume and when you want to type brackets. Perhaps you should re-consider your hotkey choice. If you were to go with holding down Ctrl/Alt/Shift/Win + [ or ], you wouldn't have this problem. I, personally, would go with one of the following sets:

Code: Select all

#[::VolumeDown           ; Win + [
#]::VolumeUp             ; Win + ]

#Down::VolumeDown        ; Win + Down Arrow
#Up::VolumeUp            ; Win + Up Arrow

#PgDn::VolumeDown        ; Win + PageDown
#PgUp::VolumeUp          ; Win + PageUp
Kamil KW
Posts: 7
Joined: 21 Nov 2017, 11:31

Re: How to avoid loops with Volume up an down

21 Nov 2017, 21:19

Yes, I agree with you. But I simply found it very annoying to need to press additional keys, so I prefer to press just one key to get the volume, and then an extra key to get that character that I don't need more often than once a month.

Also, when I use the extra key (eg. CRTL + up/down or page up/down) to control volume, sometimes I get conflicts while scrolling pages. So if there is a way to get volume control with one key, and then CTRL or ALT + that key to get the bracket (or other character that's assigned to volume control), that would be ideal.

Any suggestions? I would appreciate it, indeed.
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: How to avoid loops with Volume up an down

21 Nov 2017, 21:39

Oh, I see. It sounds like you want:

Code: Select all

~[::VolumeDown
~]::VolumeUp

^[::Send, [
^]::Send, ]
You would then press Ctrl + [ to type a [ and Ctrl + ] to type a ].
Kamil KW
Posts: 7
Joined: 21 Nov 2017, 11:31

Re: How to avoid loops with Volume up an down

22 Nov 2017, 06:58

Unfortunately, this does not work (I have already tried this and a few similar). This script still changes volume when I press CTRL+bracket.

And, for the record, you forgot the underscore after volume before up and down ;-)

Volume_Up

Also, the ~ causes the volume change and the typing at the same time - not ideal.

Any other ideas?
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

Re: How to avoid loops with Volume up an down

22 Nov 2017, 07:07

As in my first reply, you need the $ prefix to stop ^[::Send, [ from triggering ~[::VolumeDown

Code: Select all

$~[::VolumeDown
$~]::VolumeUp

^[::Send, [
^]::Send, ]
That's not ideal either as now it does two things at the same time: it turns the volume up (or down) and types the character
Then do not prefix the hotkey with ~

Code: Select all

$[::VolumeDown
$]::VolumeUp

^[::Send, [
^]::Send, ]
Kamil KW
Posts: 7
Joined: 21 Nov 2017, 11:31

Re: How to avoid loops with Volume up an down

22 Nov 2017, 11:31

Unfortunately, that does not work either. With that script (and the correct Volume_up and _down command), pressing CTRL bracket results in volume control, not the bracket as you would expect. So what gives?
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

Re: How to avoid loops with Volume up an down  Topic is solved

22 Nov 2017, 11:46

Kamil KW wrote:Unfortunately, that does not work either. With that script (and the correct Volume_up and _down command), pressing CTRL bracket results in volume control, not the bracket as you would expect. So what gives?
Tested the following code and it does not behave how you describe

Code: Select all

$[::Send {Volume_Down}
$]::Send {Volume_Up}

^[::Send, [
^]::Send, ]
Hold Ctrl, hit [ and it types [ and voume does not change
Hit [ on it's own, volume changes and [ is not typed

Image
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: How to avoid loops with Volume up an down

22 Nov 2017, 11:53

evilC wrote:

Code: Select all

$]::Volume_Up
$[::Volume_Down
+]::]
+[::[
Kamil KW wrote:Thanks. We have some progress, but not there yet - when I press shift and a bracket, I get now { or }, but still no square brackets. Any idea?
So the resolution to this would've been changing the bottom two remaps into hotkeys. Remaps preserve the modifier that activated them, which in this case was a Shift, and Shift+] normally makes }. So it really didn't accomplish anything. Instead, you'd want this:

Code: Select all

$]::Volume_Up
$[::Volume_Down
+]::Send ]
+[::Send [
That should work. I think this was suggested at some point recently though. Otherwise, like I know was just posted above me is to make all 4 into hotkeys.

Edit: I tested it because issues were apparently run into. I'll have to explore, but I was able to repeat the issue that with the code I gave above, indeed... DUH.

Two options:

Code: Select all

$]::Send {Volume_Up}
$[::Send {Volume_Down}
+]::Send ]
+[::Send [
or

Code: Select all

+]::Send ]
+[::Send [
$]::Volume_Up
$[::Volume_Down
What I overlooked is that remaps don't just preserve the modifier you pressed as if one was required, but it also allows the remap to be activated by any modifier. The remaps on top were taking priority over the hotkeys on bottom!

So why does the first code work? Because it is purely hotkeys now. Shift+] can only activate the hotkey on the third line. The top hotkey is only activated if ] alone is pressed.

So why does the second code work? Because the hotkeys are now listed above the remaps, which gives them a higher priority. Shift+] will activate the hotkey, not the remap.
Kamil KW
Posts: 7
Joined: 21 Nov 2017, 11:31

Re: How to avoid loops with Volume up an down

22 Nov 2017, 15:48

Man, you're a super star. Your code works like a treat:

Code: Select all


$[::Send {Volume_Down}
$]::Send {Volume_Up}

^[::Send, [
^]::Send, ]

Big cheers, bro!

Kamil

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: garry, marypoppins_1, mikeyww and 119 guests