Fixed: Support for > 3 Mouse Buttons as Hotkeys

Started by Simon, December 16, 2024, 03:09:29 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Simon

Hi,

Lix test executable for many mouse buttons

This adds support for more than 3 mouse buttons.

Do you have a mouse with extra buttons? Please try this (put it into a full Lix tree, e.g., from a fresh download). Bind your extra mouse buttons to some skills or functions. Will the bound mouse buttons work during play?

Silken, please turn off your external mouse-to-keyboard binding tool for this test. Lix should really see you mouse buttons as-is, not as keyboard keys.

This doesn't yet export the new bindings to the options file. As a result, this version of Lix doesn't remember the extra mouse button bindings after you exit and restart Lix. Before we can merge this, I'll have to decide how exactly to export/import mouse button bindings from the options file.

-- Simon

Simon

Simon: 1. Ensure that manufacturer's software is running. 2. Ensure that you don't bind any mouse buttons to keyboard keys in it. 3. Run Lix. 4. Bind the extra mouse buttons in Lix. 5. Tell me if Lix accepts those keybindings.

SilkenHealer: That's what I was already doing.

Simon: Okay, and Lix fails to accept the bindings then?

SilkenHealer: Yeah.

Simon: And Lix also fails to accept the binding if you replace step 1 with (ensure that the manufacturers's software is not running).

SilkenHealer: Yeah.

Simon: Okay, then it fails altogether and I should find a mouse with many buttons to test it myself first. I don't have such a mouse unfortunately, but I'm happy that you were up for the quick test.

-- Simon

WillLem

My mouse has 5 buttons. I tested with the following:

Left = (normal actions)
Middle = Pause
Right = Back 1 tick
X1 = Back 1 second
X2 = Fast forward

All seems to be working great, no issues.

Simon


Silken Healer

Update: I got it to work if I set my fourth and fifth mouse button to the default, forward and backwards in the manufactuers' software

Silken Healer

Update 2: Even if I set other buttons then the 2 on the sides to "Forwards" or "Backwards" in the manufactures software Lix recognizes them as MB4/5

Hypothesis to what's happening: could it be because most mouse that have extra buttons by default set the first extra 2 to be "Forwards" and "Backwards," so Lix is waiting for the Forwards/Backwards input, and not the inherent initial button press?

Simon

All right, thanks for the two of you to confirm that there is new working functionality in the experimental!

Next task for me is to persist the new bindings in the options file user/options.sdl.

In addition to a future-proof differentiation between keyboard key IDs, mouse button IDs, and wheel directions, I'll also save the old IDs for RMB, MMB, wheel up/down. This allows new option files to work with old Lix.

The old IDs for RMB, MMB, wheel up/down are prone to theoretical conflicts with extra keyboard keys from far-future Allegro 5 updates. I'd like to eventually ditch this backward-compatible saving in 3-6 years. But for now, it's better to have backward-compatible option files.

QuoteUpdate 2: Even if I set other buttons then the 2 on the sides to "Forwards" or "Backwards" in the manufactures software Lix recognizes them as MB4/5

Which buttons are "them"?

Quote from: Silken Healer on December 16, 2024, 09:43:37 PMHypothesis to what's happening: could it be because most mouse that have extra buttons by default set the first extra 2 to be "Forwards" and "Backwards," so Lix is waiting for the Forwards/Backwards input, and not the inherent initial button press?

I'm only reacting Allegro 5's events for mouse button down, and for mouse button up. I receive a button ID (an integer ≥ 1) for each, and no other information. I'd have to dive into Allegro 5's Windows-specific mouse implementation to tell you more.

-- Simon

Silken Healer

Quote from: Simon on December 17, 2024, 03:05:53 AMWhich buttons are "them"?
Any other than left click, right click, middle click, or the two on the sides labelled as button 4 and 5

Simon

Quote from: Simon on December 17, 2024, 03:05:53 AMpersist the new bindings in the options file user/options.sdl.
also save the old IDs for RMB, MMB, wheel up/down.

Done, and earmarked for the next Lix release 0.10.28.

-- Simon

Silken Healer

The feature doesn't really work properly though?

Simon

What fails?

It sounds like your manufacturer's software swaps the buttons around before Windows sees them. That software's reasoning seems to be: Browsers react to MB4 (with page-back) and to MB5 (with page-forward), and you want MB6 to be page-back in the browser, therefore the software makes Windows believe that MB6 is MB4.

What do you expect Windows to see from your mouse, possibly through the manufacturer's software?

What do you expect Lix to see from Windows through Allgero?

Where in the chain (from hardware to Lix) do you see a bug?

-- Simon

Silken Healer

As I said in a previous post, Lix should react to the inherent initial mouse button, not the browser "Forwards"/"Backwards" action. Due to my testing, I believe the problem is Lix is reacting for the "Forwards"/"Backwards" action, not the inherent initial mouse button.

That's not even starting on how would people use MB6+ in Lix.

Simon

QuoteLix should react to the inherent initial mouse button

I'd have to bypass your operating system's drivers (including your manufacturer's software) and write my own driver for your hardware and read your hardware's raw output.

Quotenot the browser "Forwards"/"Backwards" action

Lix sees no such named action. All Lix sees is button IDs.

If your manufacturer's software calls MB4 "browser backwards" when it swaps your buttons, that doesn't change that Lix sees the already-swapped integers, not meaningful names.

-- Simon

Silken Healer

Quote from: Simon on December 18, 2024, 05:30:14 AMI'd have to bypass your operating system's drivers (including your manufacturer's software) and write my own driver for your hardware and read your hardware's raw output.

I'm sorry if you thought I was being selfish and only wanted it for me. I thought it was not working as you intended for anybody. If you think it is not broken, then feel free to release it.

You do realize that the Mouse Button 4/5 aren't necessarily "Forwards"/"Backwards" by default and can just be Mouse Button 4/5, right? That might be where the confusion lies

Simon

#14
Right, we agree that MB4 isn't necessarily browser-backwards.

Browsers may react to MB4 by executing their page-back function; we don't care, Lix isn't a browser.

Your manufacturer's software sees MB4, and calls MB4 "browser backwards". We don't care ... or do we? Does that software fire some sort of non-mouse-button event that browsers somehow catch? Who knows exactly what your software does. I assume that it fires no such event. I assume it acts like a driver, swapping the button presses before your OS exposes the button presses to applications.

Now what exactly happens to your MB4 input that doesn't happen to WillLem's MB4 input? WillLem's X1 is MB4 (different name) and WillLem can bind MB4 successfully in Lix. If you think that Lix has the bug (instead of that your software is misconfigured or buggy), sure, that's possible, but then why does WillLem succeed in binding MB4 in Lix?

-- Simon

Silken Healer

Perhaps WillLem's fourth and fifth mouse button can also be used to go back and forward in a browser?

I am sorry, I am not an expert on how exactly it works. But surely it's a bug in Lix if I had to change my settings in my manufactuers' software on a hunch to get it to work, can use this to get physically different buttons to react as the 4th and 5th, and this only supports <= 5 buttons?

and to be clear, I'm not saying this because I personally want it. I personally didn't mind doing it the old way. I just don't want it to be a bug for the greater good of Lix.

Quote from: Simon on December 18, 2024, 05:55:38 AMYour manufacturer's software sees MB4, and calls MB4 "browser backwards".

It doesn't. It calls it mouse button 4 and 5, and then I select what I want it do, e.g. press the left arrow, press the right arrow, do the "Forwards" action, do the "Backwards" action, etc.

Simon

QuoteBut surely it's a bug in Lix if I had to change my settings in my manufactuers' software on a hunch to get it to work, can use this to get physically different buttons to react as the 4th and 5th, and this only supports <= 5 buttons?

Doesn't follow.

Situation 1: Your environment is fine and Lix has a bug. You reconfigure to work around half of the bug.

Situation 2: Your environment is a jumbled mess and Lix is bug-free. Then you reconfigure the environment and solve a part of the problem.

Your findings don't distinguish between these two situations.

QuoteI select what I want it do, e.g. press the left arrow, press the right arrow, do the "Forwards" action, do the "Backwards" action, etc.

Okay, then it does react to mouse buttons by firing non-button events. It doesn't merely swap buttons. Now we want to see if it eats the input for good, i.e., if it prevents the raw mouse button press event from seeping through to Lix.

What's the exact name of that software? Who made it?

-- Simon

Silken Healer


Silken Healer

Quote from: Simon on December 18, 2024, 06:35:58 AMDoesn't follow.

Situation 1: Your environment is fine and Lix has a bug. You reconfigure to work around half of the bug.

Situation 2: Your environment is a jumbled mess and Lix is bug-free. Then you reconfigure the environment and solve a part of the problem.

That is why I said it's an hypothesis

Simon

Reddit: set the side buttons to just Mouse 3 and 4 and not "Forward" and "Back"?

He couldn't solve it in G-Hub. This is the closest-looking problem that I've found by websearching. It's from August 2022.

I'm inclined to blame your problem on G-Hub.

People on the internet are annoyed with G-Hub in general. But most complain that G-Hub switches erratically between profiles when it should stick with its current one. That's unrelated here.

-- Simon

Simon

#20


MS reference for winuser.h: This part of the Win32 API offers only 5 buttons, RI_MOUSE_BUTTON_1_DOWN through RI_MOUSE_BUTTON_5_DOWN, and no more than those 5. And Allegro calls into that API: Allegro 5's Windows mouse event generator looks at these 5 buttons, and at no more.

I don't know if Lix can even see more than 5 buttons on Windows. I'd have to ask the Allegro devs.

Curiously, WillLem tested exactly 5 buttons.

-- Simon

Silken Healer

I am so confused. Is this a bug with Lix or something else? Does Mouse Button 4/5 do it's own action or Forwards/Backwards?

Quote from: Simon on December 18, 2024, 11:40:22 AM
That cat looks so scary

Simon

#22
Mouse --hardw-protocol--> Windows --Win32-API--> Allegro 5 --A5-API--> Lix
Hardware                  v     ^                DLLs in Lix       my code
                          >G-Hub^

The first culprit is the anemic mouse hardware protocol between the mouse hardware and Windows, i.e., what travels through the mouse's cable. There is a standard way for mice to send the first 5 buttons to Windows. Mouse manufacturers and Microsoft's designers have never sat down to agree on a standard hardware protocol beyond 5 buttons.

From the 6th button onward, the mouse is on its own. When you press the hardware button MB6, your mouse sends some Logitech-specific signal. G-Hub accepts that and knows that you pressed MB6.

The second culprit -- and IMHO the main culprit -- is that Windows doesn't offer an application-side standard way to offer more than 5 buttons. The Win32 API exposes 5 buttons, no more. Even if G-Hub understands your mouse hardware perfectly, G-Hub (which works like a driver here) can't encourage Windows to offer to applications (via the Win32 API) your mouse's MB6 as MB6. G-Hub can only encourage Windows to offer your MB6 as MB5, or to offer your MB6 as some keypress.

Now, when G-Hub presents your incoming button press (from the mouse to Windows) of MB6 as an outging (from Windows to applications) button press of MB5, G-Hub doesn't call it "MB5", it calls it "browser forward".

Allegro reads up to 5 buttons from the Win32 API. (Remember that Win32 only exposes 5.) Allegro reads MB1 through MB5, and what comes in as MB5 is what you sent from G-Hub as "browser forward". Allegro will never think that MB6 is pressed. As long as Allegro sticks with calling the Win32 API (and that looks reasonable), it will be impossible for Allegro to receive MB6 from Windows.

My usercode in Lix (my code that calls the Allegro 5 API) reads up to 30 mouse buttons from Allegro, but Allegro will, on Windows, only ever give me the first 5. Lix believes that there are 30 buttons and that the upper 25 are never pressed.

-- Simon

Silken Healer

So let me get this straight. There's no such thing as a "Forward"/"Backwards" action, there is just Mouse Button 4/5, browsers typically react to Mouse Button 4/5 with backwards/fowards, but that's not the action of the button, and when Logitech G Hub acts like a "Forwards"/"Backwards" action exists, it's actually just making Mouse Button 4/5 be on a different physical button under the hood, and there was no bug in the first place?

Simon

I believe that everything you say in your reply #23 is correct, yes.

There is one far-fetched theory that I can't refute: G-Hub might send a special go-back command in addition to sending MB4/MB5. But I don't know about such a special command. I'd also assume that, if browsers saw such an extra command, the browser would go back twice: Once for the special command, once for the MB4.

But I think: All that G-Hub feeds into your system (when you configure someting to "backwards"/"forwards") is MB4/MB5, and therefore I think you're right.

-- Simon

Silken Healer

Sorry for wasting your time then if there was no bug in the first place  :-[

Simon

All good. Thanks for prodding me to drill into Allegro 5's source and the Win32 API, and understand that only 5 buttons can ever get through to Lix on Windows. I've learned something new.

-- Simon

Silken Healer

Quote from: Simon on December 19, 2024, 01:01:22 AMI've learned something new.
Me too



In follow-up though, for MB6+, what people typically do is in their manufactures software (or some other software that can do so) they'll set their MB6+ to a F13+ key. These keys are typically never on any keyboards, but you can technically buy keyboards that have them. But what they do is they use F13+ as a sort of "temp" key. Then, they can do things with the F13+ key as it's supported.

So should there be a way to add to keys you don't have in the Lix controls setting, by pressing a button to select a key from the list of options, or at least give the keys in the options.sdl names based on what they are rather than the number so people can edit the file in a text editor to add F13+ keys

Simon

In any version of Lix (stable or experimental), please try;

  • In G-Hub, bind MB6 to F13.
  • In user/options.sdl, bind the builder skill to number 145.
  • Play a Lix level with builders. Does MB6 select builder?

-- Simon

Silken Healer

It works, but it says "145" under the image of the Lix building in the skill bar in grey not "F13"

Simon

Quoteit says "145" under the image of the Lix building in the skill bar in grey not "F13"

Okay, that is easy to fix for me in Lix.

QuoteIt works

Great! Now:

  • Go into Lix's options menu, and go to the builder icon.
  • Press the minus button under the builder until nothing is bound to builder.
  • Click the blank button under builder.
  • Press MB6 on the mouse.
  • Has Lix accepted MB6 as a new keybinding for the builder, i.e., the button again says "145"?

-- Simon

Silken Healer

Yes. It says "145" here too.

Also I just realized something. If people set their extra mouse buttons to F13+ in their manufactues' software, you don't need to edit the options.sdl in a text editor. You can just press that button to do F13. So you don't need to add anything or change anything to make this work. I feel so stupid I can't believe that slipped my mind.

I just did this on a fresh copy of Lix to test it that has never had it's options.sdl edited and it has the same behaviour of it working but showing the number "145" in grey

Simon

#32
All right, cool. I've given the names F13 through F24 for the internal Allegro key codes 145 through 156. Earmarked for 0.10.28.

Quoteextra mouse buttons to F13+ in their manufactues' software, you don't need to edit the options.sdl in a text editor. You can just press that button to do F13.
I just did this on a fresh copy of Lix

Right, anything else would have surprised me. The upside is: You've now confirmed that binding F13 works via both of the follwing ways: Binding F13 works via options file import, and binding F13 works via the keybinding button in the options menu.

-- Simon