R+Lbutton = MButton, Rbutton+Wheel = Volume?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
reyn
Posts: 57
Joined: 21 Jul 2021, 18:08

R+Lbutton = MButton, Rbutton+Wheel = Volume?

21 Jul 2021, 18:34

As local Search is a mess constantly asking to wait, and i already spent 2 hours searching and trying various scripts that stated to do what i need but actually not(don't know if those were outdated or just broken), i decided to register and ask it straight away here.
What i need is simply 2 functions:
- when L+Rbutton pressed together = Mbutton is sent
- when Rbutton is held and wheel scrolled = volume changes upd/down

just as an example that i did try searching, here one of variant that did not work for me:

Code: Select all

RButton & LButton::Click, middle
LButton & RButton::Click, middle
RButton::Click, right
LButton::Click, left
User avatar
mikeyww
Posts: 26592
Joined: 09 Sep 2014, 18:38

Re: R+Lbutton = MButton, Rbutton+Wheel = Volume?

21 Jul 2021, 21:35

What happens when you press the buttons together?

Have you tried SoundSet in conjunction with RButton & WheelDown?
reyn
Posts: 57
Joined: 21 Jul 2021, 18:08

Re: R+Lbutton = MButton, Rbutton+Wheel = Volume?

22 Jul 2021, 03:22

mikeyww wrote:
21 Jul 2021, 21:35
What happens when you press the buttons together?
Either nothing happens or context menu opens. I thought it's could be due to next 2 commands stating lbutton and rbutton to keep their normal functions, but tried this code and nothing again

Code: Select all

RButton & LButton::Click, middle
LButton & RButton::Click, middle
return
RButton::Click, right
LButton::Click, left
return
Was thinking about a "hold rbutton for more than 2 sec" or "hold rbutton + click lbutton", but didn't find working example. Plus as i understand one script can't have two functions working around holding rbutton..

mikeyww wrote:
21 Jul 2021, 21:35
Have you tried SoundSet in conjunction with RButton & WheelDown?

Code: Select all

RButton & WheelDown :: SoundSet, -1
RButton & WheelUp :: Send {Volume_Up}
"Error: Invalid hotkey" and it's not about volume/right part, tried simple <::MsgBox, a>, same error.
User avatar
mikeyww
Posts: 26592
Joined: 09 Sep 2014, 18:38

Re: R+Lbutton = MButton, Rbutton+Wheel = Volume?

22 Jul 2021, 06:09

First issue: would try in a different target program. For a simple test, you can change the command to a simple send command, and test it in Notepad to see that it works.

Second issue: hotkeys are followed by :: rather than a space.

I suggest working on one problem at a time. Delete the final two lines so that you can fix the first problem first.

Try the following script without other code in Notepad.

Code: Select all

RButton & LButton::
LButton & RButton::Send x
RButton::RButton
LButton::LButton
reyn
Posts: 57
Joined: 21 Jul 2021, 18:08

Re: R+Lbutton = MButton, Rbutton+Wheel = Volume?

24 Jul 2021, 13:17

found the reason of all problems. first thought it was smth about UAC, but as i'm noob with AHK i simply didn't know one script can't have two places using same button(as launcher said nothing i thought there is no problem, but eventually i found out that parts that didn't work shared Rbutton use).
kinda disappointing limitation, wanted to gather few useful features for me in one script. well i still can do if will get an idea how to not use Rbutton in both.

meanwhile, hope you can help me with few things please.

Code: Select all

~RButton::
now := A_TickCount
while GetKeyState("RButton", "P")
	if (A_TickCount-now > 200)
	{
	Click, Middle
	Return
	}
not my code, suits my needs. problem is sometimes in some apps right-click happens after long press and context menu opens. is there some way to forbid that one extra R-click?

yet, still didn't find good script for global volume control with visualisation at least via tooltips or better some OSD - if it may happen you know any, please share a link.
User avatar
mikeyww
Posts: 26592
Joined: 09 Sep 2014, 18:38

Re: R+Lbutton = MButton, Rbutton+Wheel = Volume?

24 Jul 2021, 22:43

It isn't a limitation. It's a feature, because if you had two identical hotkeys without any context, the script would not know which routine to execute.

The tilde permits the native key to execute. Thus, to remove that feature, remove the tilde. Another solution for certain circumstances is KeyWait. You can always have a mouse hotkey send its own button, too, within the routine.
reyn
Posts: 57
Joined: 21 Jul 2021, 18:08

Re: R+Lbutton = MButton, Rbutton+Wheel = Volume?

25 Jul 2021, 06:18

mikeyww wrote:
24 Jul 2021, 22:43
It isn't a limitation. It's a feature, because if you had two identical hotkeys without any context, the script would not know which routine to execute.
can't agree on that, understanding the difference in R-hold+L-click and R-hold+wheel shoudn't be a problem to be used i one code. but as AHK doesn't have nested conditions i guess it's really a "politics of simplicity"...

mikeyww wrote:
24 Jul 2021, 22:43
The tilde permits the native key to execute. Thus, to remove that feature, remove the tilde. Another solution for certain circumstances is KeyWait. You can always have a mouse hotkey send its own button, too, within the routine.
i still don't get it. here's another example:

Code: Select all

RButton::
Time:=400
if (A_PriorHotkey = "RButton" and A_TimeSincePriorHotkey < Time)
{
	Click Middle
    	Return
}
else
{
	Click Right	
	Return
}
Return
what i expect: right click doesn't work 'cause no tilde, each time i R-click it first checks for A_TimeSincePriorHotkey and last hotkey, if it was fast double-R-click script sends M-click and that's all, ONLY if both conditions don't work it goes to next part and simply R-click.
what happens: i make double-R-click, context menu appears for part-second(like First Priority conditions aren't there), and then M-click happens.
where is no-tilde blocking native function?!
Last edited by gregster on 25 Jul 2021, 06:27, edited 1 time in total.
Reason: quote tags fixed.
User avatar
mikeyww
Posts: 26592
Joined: 09 Sep 2014, 18:38

Re: R+Lbutton = MButton, Rbutton+Wheel = Volume?

25 Jul 2021, 07:52

The problem with your script is that after the first click, there is no check to see what happens next-- but this is in your description of what should happen, and it is necessary because you have alternative actions for the two different situations.

Code: Select all

RButton::
KeyWait, RButton
KeyWait, RButton, DT.4
Send % ErrorLevel ? "{RButton}" : "{MButton}"
Return
If you want to include the right click with the middle click, then it can be done differently.

Regarding your first comment: AHK distinguishes buttons from wheel.

Code: Select all

RButton & LButton::
LButton & RButton::Send 1
RButton & WheelDown::Send 2
RButton::RButton
LButton::LButton
reyn
Posts: 57
Joined: 21 Jul 2021, 18:08

Re: R+Lbutton = MButton, Rbutton+Wheel = Volume?

25 Jul 2021, 09:28

mikeyww wrote:
25 Jul 2021, 07:52

Code: Select all

RButton::
KeyWait, RButton
KeyWait, RButton, DT.4
Send % ErrorLevel ? "{RButton}" : "{MButton}"
Return
this code does exactly what i wanted for M-click, thank you!
but can you please explain what happens here: % ErrorLevel ?, so i understand how it works.
mikeyww wrote:
25 Jul 2021, 07:52
Regarding your first comment: AHK distinguishes buttons from wheel.
but no nested conditions, am i right? like: if{ if{} }.
User avatar
mikeyww
Posts: 26592
Joined: 09 Sep 2014, 18:38

Re: R+Lbutton = MButton, Rbutton+Wheel = Volume?

25 Jul 2021, 10:24

The ternary operator is simply like "If... then... else". Thus, it is, "If the button was pressed again within 0.4 seconds, send MButton; otherwise (when ErrorLevel is set), send RButton. More literally: "IF ErrorLevel is neither zero nor null (because the button was not pressed again within 0.4 seconds), THEN send RButton, ELSE send MButton".

Sure, you can combine conditions. What are you trying to accomplish with it?

Code: Select all

If (1=1 && 2=2)
 Send x
 
If (1=1)
 If (2=2)
  Send y
It is fine to add braces where needed.
reyn
Posts: 57
Joined: 21 Jul 2021, 18:08

Re: R+Lbutton = MButton, Rbutton+Wheel = Volume?

25 Jul 2021, 10:57

mikeyww wrote:
25 Jul 2021, 10:24
More literally: "IF ErrorLevel is neither zero nor null (because the button was not pressed again within 0.4 seconds), THEN send RButton, ELSE send MButton".
Thank you for explanation, still didn't get what % corresponds to - it's a "neither zero nor null" stance?
mikeyww wrote:
25 Jul 2021, 10:24
Sure, you can combine conditions. What are you trying to accomplish with it? It is fine to add braces where needed.
FFor the moment nothing particular, it's just i couldn't make it work with nested IF and braces while experimenting. Probably need read more about syntax, 'cause for example i still don't understand why sometimes braces aren't present at all, like in your examples.
User avatar
mikeyww
Posts: 26592
Joined: 09 Sep 2014, 18:38

Re: R+Lbutton = MButton, Rbutton+Wheel = Volume?

25 Jul 2021, 12:36

Feel free to post your new script with braces.

See documentation about forced expressions. It is just a way to provide an expression when an AHK command is otherwise expecting a literal string. An example is below.

Code: Select all

Send Item 1: 3`n
Send Item 2: 1 {+} 2`n
Send Item 3: `
Send % 1+2
Send `nItem 4: 1+2
reyn
Posts: 57
Joined: 21 Jul 2021, 18:08

Re: R+Lbutton = MButton, Rbutton+Wheel = Volume?

31 Jul 2021, 01:32

mikeyww wrote:
25 Jul 2021, 07:52

Code: Select all

RButton::
KeyWait, RButton
KeyWait, RButton, DT.4
Send % ErrorLevel ? "{RButton}" : "{MButton}"
Return
can you please modify script of yours to allow R-hold drag?(currently it doesn't work while script is running)
User avatar
mikeyww
Posts: 26592
Joined: 09 Sep 2014, 18:38

Re: R+Lbutton = MButton, Rbutton+Wheel = Volume?

31 Jul 2021, 07:47

Code: Select all

RButton::
KeyWait, %A_ThisHotkey%, T0.2          ; Wait for release
If ErrorLevel {                        ; Button was HELD instead
 Click, R D
 KeyWait, %A_ThisHotkey%
 Click, R U
 Return
} Else KeyWait, %A_ThisHotkey%, DT0.2  ; Wait for second press
Click, % ErrorLevel ? "R" : "M"
Return
reyn
Posts: 57
Joined: 21 Jul 2021, 18:08

Re: R+Lbutton = MButton, Rbutton+Wheel = Volume?

02 Aug 2021, 05:18

many thanks for modification, works good!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: garry, marypoppins_1, mikeyww, RussF and 152 guests