joystick button combo binding?

By Cayce

Resident (34)

Аватар пользователя Cayce

03-01-2021, 15:18

Is it possible to bind multiple joystick button presses to an openMSX action?

At https://openmsx.org/manual/commands.html#bind I see a 'hint' towards combos being supported in the 'bind ALT+RETURN' example, but e.g. bind "joy1 button8 up"+"joy1 button9 up" or bind "joy1 button8 up+joy1 button9 up" cause a syntax error. Is this feature only available for keyboard events?

On my Linux machine I run openMSX 0.15.0, on my RetroPie package 0.15.0-2 is installed (although openmsx -v reports "openMSX 16.0-unknown").

As background, I'm trying to mimick the RetroArch hotkey function in openmsx. On RetroPie+8bitdo I press Logo+Start to exit, Logo+B to reset, etc. I can successfully bind single joystick buttons to actions (like toggle_freq, exit, etc.) but I quickly run out of buttons ;-) Plus I'd like to have the same behaviour on RetroArch apps and non-RetroArch.

BTW this is my first post. I searched for this issue on the web, this forum & tried it myself, but could not find a solution. I saw many helpful hints on this forum for other issues I had, so I'm hoping anyone will be kind enough to help me out with this (apparently) new one. Thanks in advance!

Для того, чтобы оставить комментарий, необходимо регистрация или !login

By wouter_

Hero (535)

Аватар пользователя wouter_

04-01-2021, 08:36

Hi Cayce,

Unfortunately what you're trying to do is not supported in openMSX. You cannot combine multiple events into one combo-binding. Also for keyboard events this is not supported. The only exception are the usual modifier keys like SHIFT, CTRL, ALT. Those can be arbitrarily combined, but only with keyboard events.

By baarreth

Supporter (4)

Аватар пользователя baarreth

15-01-2022, 18:08

Hi retro friends,

You can combo multiple joystick buttons on openmsx by binding a bind.

For example, if your SELECT button (your hotkey) is mapped as button 8, and your START button is mapped as 9, you can make SELECT+START trigger the openmsx's exit command by executing on the console:

bind "joy1 button8 down" "bind \"joy1 button9 down\" exit"
bind "joy1 button8 up" "unbind \"joy1 button9 down\""

Which in setting.xml will be stored as:

<bind key="joy1 button8 down">bind "joy1 button9 down" exit</bind>
<bind key="joy1 button8 up">unbind "joy1 button9 down"</bind>

I would like to add that you should set save_settings_on_exit off to avoid permanently bind one of the keys as the exit command. (After exiting, it will not register the release action).

Also, you can put two (or more) bindings on the same bind by using semicolon with extra spaces ( ; ):

bind "joy1 button8 down" "bind \"joy1 button9 down\" exit ; bind \"joy1 button1 down\" reset"
bind "joy1 button8 up" "unbind \"joy1 button9 down\" ; unbind \"joy1 button9 down\""

Which in setting.xml will be stored as:

<bind key="joy1 button8 down">bind "joy1 button9 down" exit ; bind "joy1 button1 down" reset</bind>
<bind key="joy1 button8 up">unbind "joy1 button9 down"  ;  unbind "joy1 button1 down"</bind>

By Manuel

Ascended (19679)

Аватар пользователя Manuel

16-01-2022, 00:21

Wow, this sounds like a brilliant idea Smile Let me think about it... and discuss with wouter_.

About the settings getting saved: you could perhaps set up an 'after quit' event which does the unbinding... (not tested whether that really helps, but it's an idea you could check out).

By baarreth

Supporter (4)

Аватар пользователя baarreth

16-01-2022, 03:24

Thank you for your suggestion!

It is really possible to put an after quit "unbind ..." inside the hotkey bind. It becomes something like this.

bind "joy1 button8 down" "bind \"joy1 button9 down\" exit  ;  after quit \"unbind \\\"joy1 button9 down\\\"\""

Or also without after:

bind "joy1 button8 down" "bind \"joy1 button9 down\" \"unbind \\\"joy1 button9 down\\\" ; exit\""

By Manuel

Ascended (19679)

Аватар пользователя Manuel

16-01-2022, 12:07

One drawback of your method is that the order in which you press the buttons is important. But that may also be a advantage if you really want that behaviour.

By baarreth

Supporter (4)

Аватар пользователя baarreth

16-01-2022, 15:41

Manuel wrote:

One drawback of your method is that the order in which you press the buttons is important. But that may also be a advantage if you really want that behaviour.

Yes. And since I am used to press both buttons at the same time on Mame and Mednafen, I must confess it is a bit annoying for me LOL! . But I think it is a small price to make the combo work in such an amazing emulator.

I also hope other people find this thread, and maybe propose a simpler or more efficient solution (Tcl? Pull request on git? who knows...).

P.S.: I think one could fix the order issue by adding binds in the inverse order. But I feel it would become unnecessarily complex (specially for multiple nested binds), and this extra load in the system every time we press a frequently used button gives me chills.

bind "joy1 button8 down" "bind \"joy1 button9 down\" exit"
bind "joy1 button8 up" "bind \"joy1 button9 down\" \"bind \\\"joy1 button8 down\\\" exit\""
bind "joy1 button9 down" "bind \"joy1 button8 down\" exit"
bind "joy1 button9 up" "bind \"joy1 button8 down\" \"bind \\\"joy1 button9 down\\\" exit\""

Which in setting.xml will be stored as:

<bind key="joy1 button8 down">bind &quot;joy1 button9 down&quot; exit</bind>
<bind key="joy1 button8 up">bind &quot;joy1 button9 down&quot; &quot;bind \&quot;joy1 button8 down\&quot; exit&quot;</bind>
<bind key="joy1 button9 down">bind &quot;joy1 button8 down&quot; exit</bind>
<bind key="joy1 button9 up">bind &quot;joy1 button8 down&quot; &quot;bind \&quot;joy1 button9 down\&quot; exit&quot;</bind>



Warning: Inside the settings.xml, the quotation marks (") are stored as &quot;... and the forum html parser screwed my comment, changing the &quot; to actual ". I think it is ok in this post, but they are wrong in the first one (which I cannot edit, since it is my first post in this forum).