XButton with 2 or more mouse button hotkeys

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
koolestani
Posts: 76
Joined: 15 Jun 2020, 04:22

XButton with 2 or more mouse button hotkeys

18 May 2021, 22:21

Can anyone help me understand as to why these are invalid hotkeys:
I mean I get it; who would in their right minds want to map hotkeys in this crazy manner, but I only intend to use some of these combinations; as I can't possibly remember anything more than 4-5 out of these anyway.

Also I should mention that the script already makes use of hotkeys like XButton1 & WheelUp, so how can conflicts of bigger hotkeys containing these bits in them be dealt with? I tried using the dollar sign, but to no avail.

To my surprise the order of the hotkeys does matter and can make 2 hotkeys that appear to be similar function differently Xbutton2 & Xbutton1 and XButton1 & XButton2 are actually 2 different hotkeys

Code: Select all

XButton2 & LButton & WheelUp
XButton2 & LButton & WheelDown

XButton2 & RButton & WheelUp
XButton2 & RButton & WheelDown

XButton2 & LButton & RButton & WheelUp
XButton2 & LButton & RButton & WheelDown

Code: Select all

XButton1 & LButton & WheelUp
XButton1 & LButton & WheelDown

XButton1 & RButton & WheelUp
XButton1 & RButton & WheelDown

XButton1 & LButton & RButton & WheelUp
XButton1 & LButton & RButton & WheelDown

Code: Select all

XButton2 & XButton1 & WheelUp
XButton2 & XButton1 & WheelDown

XButton2 & XButton1 & LButton & WheelUp
XButton2 & XButton1 & LButton & WheelDown

XButton2 & XButton1 & RButton & WheelUp
XButton2 & XButton1 & RButton & WheelDown

XButton2 & XButton1 & LButton & RButton & WheelUp
XButton2 & XButton1 & LButton & RButton & WheelDown

Code: Select all

XButton1 & XButton2 & WheelUp
XButton1 & XButton2 & WheelDown

XButton1 & XButton2 & LButton & WheelUp
XButton1 & XButton2 & LButton & WheelDown

XButton1 & XButton2 & RButton & WheelUp
XButton1 & XButton2 & RButton & WheelDown

XButton1 & XButton2 & LButton & RButton & WheelUp
XButton1 & XButton2 & LButton & RButton & WheelDown
User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: XButton with 2 or more mouse button hotkeys

18 May 2021, 22:27

They are invalid because AHK does not recognize more than two keys separated by &. In other words, the syntax is invalid, because the syntax is invalid!

For the third key, you can still use an #If directive with a GetKeyState.

Explained: Combinations
koolestani
Posts: 76
Joined: 15 Jun 2020, 04:22

Re: XButton with 2 or more mouse button hotkeys

18 May 2021, 22:38

Ok thanks for the quick reply, so what syntax can be used to combine these into a hotkey?
I'm sorry I didn't quite get the #If suggestion, I'm really not well versed with AHK.
User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: XButton with 2 or more mouse button hotkeys

19 May 2021, 06:07

One example is below.

Code: Select all

#If GetKeyState("LButton", "P")
XButton1::XButton1
XButton1 & WheelUp::
Send {LButton up}x
SetTimer, Done, -500
Return
#If
Done:
Send {XButton1 up}
Return
koolestani
Posts: 76
Joined: 15 Jun 2020, 04:22

Re: XButton with 2 or more mouse button hotkeys

19 May 2021, 10:10

Ok, I cant say i understand how that helps me implement it in my context.
All i need is one example for my that fits my situation.

Perhaps someone else can offer some solution as well.
User avatar
boiler
Posts: 16923
Joined: 21 Dec 2014, 02:44

Re: XButton with 2 or more mouse button hotkeys

19 May 2021, 10:40

So instead of asking mikeyww for an explanation or a different example (or thanking him), you're asking for someone else to answer? I suggest that the best way to get help on the forum is to show some appreciation for the help you're getting.
User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: XButton with 2 or more mouse button hotkeys

19 May 2021, 11:40

Thank you, boiler!

What the script does: presses "x" when the buttons & wheel are activated (pressed). It sounds like you need something different. If so, you can describe it, so that readers may respond more specifically.

When someone offers a script, you can try it (if it looks reasonable). If it does not meet your need, it sometimes helps to say, "The script does ____, but I'd like my script to do _____ instead".
koolestani
Posts: 76
Joined: 15 Jun 2020, 04:22

Re: XButton with 2 or more mouse button hotkeys

19 May 2021, 11:57

I'm sorry if there has been a misunderstanding.
In most of my posts mikey is the first responder and i do appreciate the help.
I understand that answering hundreds or even thousand of queries every day is not an easy task.
I did thank him here as well.
I just did not understand how I can use the solution offered in my case since I'm not an expert.
I didn't mean any disrespect and I don't know why asking someone else to also offer any solution or suggestion should offend him or anyone else.
I don't like to be a bother and really do try my best to find solutions to my problems if they already exist before I post a query here.
koolestani
Posts: 76
Joined: 15 Jun 2020, 04:22

Re: XButton with 2 or more mouse button hotkeys

19 May 2021, 12:14

From what I can grasp (please let me know if its incorrect)
The script basically means:
If LButton is pressed
Then XButton1 sends XButton1
However XButton1 & WheelUp sends X (after making the computer think LButton was released/lifted up?)
Can you explain the remaining lines from SetTimer? I don't get what they are doing.

This does seem to get the job done :)
Can this be condensed down to a single line of code? Pretty much like XButton2 & LButton & WheelUp, I did try curly braces instead of &, that didn't work either.
Thank you
User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: XButton with 2 or more mouse button hotkeys

19 May 2021, 13:46

OK; no harm done. My take is that if you want a different script than the one that is offered, then the other writers will want to know what is wrong with the script, or what you need to be different, what did not work, etc.

Yes, you have the right idea about what the script does. I was finding that I needed the timer initially, but in retesting the following worked.

Code: Select all

#If GetKeyState("LButton", "P")
XButton1::XButton1
XButton1 & WheelUp::Send {LButton up}x
#If
I don't have a way to shorten it beyond that, but others might. As I mentioned, AHK does not respond as you may wish with three key names separated by &.
koolestani
Posts: 76
Joined: 15 Jun 2020, 04:22

Re: XButton with 2 or more mouse button hotkeys

19 May 2021, 14:43

Ok thanks again
How can I make this method work with hotkeys with 4 and 5 keys like the following?
XButton2 & LButton & RButton & WheelUp
XButton2 & XButton1 & LButton & RButton & WheelUp
koolestani
Posts: 76
Joined: 15 Jun 2020, 04:22

Re: XButton with 2 or more mouse button hotkeys

19 May 2021, 14:47

Thank you, the new script does work exactly like the old one as far as i can tell.
User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: XButton with 2 or more mouse button hotkeys

19 May 2021, 14:49

Exactly how many fingers do you have?

Code: Select all

#If GetKeyState("LButton", "P") & GetKeyState("RButton", "P") & GetKeyState("XButton2", "P")
XButton1::XButton1
XButton1 & WheelUp::Send {LButton up}x
#If
koolestani
Posts: 76
Joined: 15 Jun 2020, 04:22

Re: XButton with 2 or more mouse button hotkeys

19 May 2021, 14:58

the script already makes use of hotkeys like XButton1 & WheelUp, so how can conflicts of bigger hotkeys containing these bits in them be dealt with?
I just checked, I am still facing this problem.
XButton1 & LButton & WheelUp also triggers the hotkey for XButton1 & LButton
koolestani
Posts: 76
Joined: 15 Jun 2020, 04:22

Re: XButton with 2 or more mouse button hotkeys

19 May 2021, 15:01

Code: Select all

#If GetKeyState("XButton1", "P")
LButton::LButton
LButton & WheelUp::Send {XButton1 up}{Tab}
#If
#If GetKeyState("XButton1", "P")
LButton::LButton
LButton & WheelDown::Send {XButton1 up}{+Tab}
#If
this generates error at line 6 "duplicate hotkey"
User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: XButton with 2 or more mouse button hotkeys

19 May 2021, 15:07

Yup. You listed the same context twice, with the same hotkeys in each-- an impossibility, since AHK would not know what to do. You can combine them if you like.
koolestani
Posts: 76
Joined: 15 Jun 2020, 04:22

Re: XButton with 2 or more mouse button hotkeys

19 May 2021, 15:17

haha that's such a silly mistake on my end it makes me laugh
changed it to the following and it works as intended:

Code: Select all

#If GetKeyState("XButton1", "P")
LButton::LButton
LButton & WheelUp::Send {XButton1 up}{Tab} ; Tab
LButton & WheelDown::Send {XButton1 up}+{Tab} ; Shift+Tab
#If
still the issue of smaller hotkeys within these bigger hotkeys getting triggered is there.
User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: XButton with 2 or more mouse button hotkeys

19 May 2021, 15:21

If you have a sequence of related contexts with #If, then list the most specific or "longest" ones first. When those do not match, the subsequent ones will have an opportunity to match. Among such a list of directives, the first match wins; that is why you want the more specific or longer ones to be listed first.
koolestani
Posts: 76
Joined: 15 Jun 2020, 04:22

Re: XButton with 2 or more mouse button hotkeys

19 May 2021, 15:24

Ok, thank you
I will try to come up with a script that does what i'm looking for now. This is starting to hurt my head :lol:
koolestani
Posts: 76
Joined: 15 Jun 2020, 04:22

Re: XButton with 2 or more mouse button hotkeys

19 May 2021, 15:30

mikeyww wrote:
19 May 2021, 14:49
Exactly how many fingers do you have?
Hahaha I swear its not as weird a script as it looks like, they are manageable which is why I'm going through the trouble of figuring it out. :lol:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: dangoscrub, doodles333, joedf, Nerafius and 88 guests