RetroArch icon indicating copy to clipboard operation
RetroArch copied to clipboard

Hotkey blocking button function in MAME/FBA cores

Open dankcushions opened this issue 11 years ago • 57 comments

Hi :)

With all non-arcade cores I've tested, there appears to be no issue with having the hotkey bound to a button with a normal function. For example, I use SNES USB controllers and use the select button as my hotkey. In SNES/NES cores, the select button functions in the game as usual (eg, to select 1 or 2 player in Super Mario), but also does all the extra hotkey functions, like select+start = quit, select+Y= retroarch GUI.

However, with every single MAME/FBA core I'm able to run (Raspberry Pi 2 + Retropie), the select button does not do its insert coin function in SOME games. Insert coin works fine if I bind it to a different button to the hotkey, but with an 8 button controller that just means you have a new problem (eg, in SFII I get a new credit every time I heavy kick :))

There are previously raised issues with the cores themselves: https://github.com/libretro/mame2003-libretro/issues/8 https://github.com/libretro/fba-libretro/issues/46 https://github.com/libretro/imame4all-libretro/issues/9 ...but according to your forums, it sounds like this is intentional (http://libretro.com/forums/showthread.php?t=4184&p=29268)? This seems wrong to me as it would mean users would not be able to use NES/SNES/PSX etc controllers in their respective cores, because you wouldn't have a spare button for a hotkey.

So my thought is that this is a core retroarch issue, where apparently the hotkey intentionally blocks the hotkey button's regular function (at least, in some cores/scenarios). Can this be changed?

dankcushions avatar Oct 11 '15 01:10 dankcushions

As I said on the forum, the fact that this works on some cores/games is a fortunate coincidence. It should not work at all.

It must be because of some timing difference on one core or another and to "fix" this the way you want it would require a lot of work on the core side or a hack in the blocking function to "whitelist" the button you want which might not be desirable.

andres-asm avatar Oct 11 '15 01:10 andres-asm

Toggle seems desirable to me? I don't think it needs to be a complex whitelist - I'd be happy with an option just turn off hotkey blocking entirely (at least, for the hotkey itself). The intended behaviour doesn't seem to work on all but a handful of cores anyway (and only sometimes!).

dankcushions avatar Oct 11 '15 01:10 dankcushions

The intended behavior works just fine! it blocks core inputs I don't jump while raising volume or anything like that. I'll try to add a toggle for the blocking mechanism as a whole but introducing use case specific hacks won't happen

andres-asm avatar Oct 11 '15 02:10 andres-asm

It blocks the behaviour of [button] in hotkey + [button], for me, but never the hotkey itself, at least for the cores i've used for systems that use a select (my hotkey) button: lr-PCSXrearmed lr-nestopia lr-snes9x-next

just tried it in super mario kart: select = toggle map/rear view L shoulder button = jump select (hotkey) + L shoulder = load state select and L function as usual in game. if i hold select and press L it changes the view but does not trigger the jump function (and I get the load state failure message, as i have no states saved).

this to me is desirable behaviour. i'd always use the hotkey as a button i press rarely as i don't want to trigger accidental saves/loads/quits, but i still want that button to perform it's usual function. Likewise, any buttons that are linked to hotkey functions, I want them to function as usual UNLESS the hotkey is held.

dankcushions avatar Oct 11 '15 02:10 dankcushions

I just tried in FBA with SFIII3 and it works like you want, also it works in snes9x so if it doesn't work in some games maybe those cores/gams react a frame later to the input or something... I don't know but I don't see a way to "fix" this

andres-asm avatar Oct 11 '15 02:10 andres-asm

the only solution I can see is only block if it's been held for more than "X ms" and that would be a horrible hack.

I can see your problem with SF2 it happens, but RA and the core are behaving exactly the same in all the cases, I guess that particular game needs the button held for more time to register a coin input and by then it's probably already being blocked.

andres-asm avatar Oct 11 '15 02:10 andres-asm

As you can see, this is not even core dependent but game dependent. Not really a RA issue.

andres-asm avatar Oct 15 '15 19:10 andres-asm

but you've confirmed the behaviour designed into retroarch is to block the native function of the button assigned to the hotkey! it just so happens that seemingly the only games where this intended behaviour happens to work in, causes problems for users, and the rest of the cores seem to bypass you're intended function, by design or accident.

i don't understand why this behaviour is part of the design (specifically blocking the hotkey's function). it doesn't make any sense, and the only area it works causes a problem.

dankcushions avatar Oct 15 '15 19:10 dankcushions

It does make sense, it was designed to use an EXTRA button as modifier.

andres-asm avatar Oct 15 '15 19:10 andres-asm

Ii don't understand how that makes a difference? Eg, using a snes controller in a snes core. I press the select button, and it does whatever select does natively in those games. I press select + X modifier, and it opens my retroarch menu. I press select + start modifier, and it quits. All that works with no issue. Why would the intended design of RA be to block the select button doing what select does natively in that core?

dankcushions avatar Oct 15 '15 19:10 dankcushions

It works on some cases because input on THAT frame and only on THAT frame already registered. After that frame input is in fact blocked and it seems in SF2 the coin button needs to be held, as simple as that.

Allowing what you want would require a bunch of hacks.

andres-asm avatar Oct 15 '15 19:10 andres-asm

i understand why it sometimes works regardless, I just don't understand why it's an intended feature of all cores, when the only times it works as intended, cause a problem.

dankcushions avatar Oct 15 '15 19:10 dankcushions

You are confusing things, this is not a core feature, input is handled by the frontend and passed into the core. Having hotkeys not block the input would cause problems like what I mentioned before.

When it doesn't work it's a problem of the program that's running inside the core, it might need the button to be held or whatever and at that point input is already blocked.

Anyway, hotkey enable blocks ALL retropad input, so it is in fact working as designed, it's not a bug, you're confusing what you want as an end user with what was actually impĺemented. A toggle to disable blocking could be implemented but an exception for a particular button is probably too much of a mess to be even considered.

andres-asm avatar Oct 15 '15 20:10 andres-asm

I think a delay or something to regiser as a hotkey would be a viable fix - I will look into this for retropie when I next have some free time, and submit upstream if anyone is interested. But I have no knowledge of the input code, so I will need to dig etc. Hack or not, this is broken for controller users currently - but I do understand the devs too.

joolswills avatar Oct 16 '15 02:10 joolswills

@joolswills i've not touched C in a decade but I think any hack/fix would be in: https://github.com/libretro/RetroArch/blob/528a020d865b6365403742e8c9631014deca4a0a/runloop.c

/**
 * check_block_hotkey:
 * @enable_hotkey        : Is hotkey enable key enabled?
 *
 * Checks if 'hotkey enable' key is pressed.
 **/
static bool check_block_hotkey(driver_t *driver, settings_t *settings,
      bool enable_hotkey)
{
   bool use_hotkey_enable;
   const struct retro_keybind *bind =
      &settings->input.binds[0][RARCH_ENABLE_HOTKEY];
   const struct retro_keybind *autoconf_bind =
      &settings->input.autoconf_binds[0][RARCH_ENABLE_HOTKEY];

   /* Don't block the check to RARCH_ENABLE_HOTKEY
    * unless we're really supposed to. */
   driver->block_hotkey             =
      input_driver_keyboard_mapping_is_blocked();

   /* If we haven't bound anything to this,
    * always allow hotkeys. */
   use_hotkey_enable                =
         (bind->key != RETROK_UNKNOWN)
      || (bind->joykey != NO_BTN)
      || (bind->joyaxis != AXIS_NONE)
      || (autoconf_bind->key != RETROK_UNKNOWN )
      || (autoconf_bind->joykey != NO_BTN)
      || (autoconf_bind->joyaxis != AXIS_NONE);

   driver->block_hotkey             =
      input_driver_keyboard_mapping_is_blocked() ||
      (use_hotkey_enable && !enable_hotkey);

   /* If we hold ENABLE_HOTKEY button, block all libretro input to allow
    * hotkeys to be bound to same keys as RetroPad. */
   return (use_hotkey_enable && enable_hotkey);
}

I think the return statement needs to be false for a few milliseconds. If it's false always it might fix our problem, but possibly with some side effects.

dankcushions avatar Oct 16 '15 09:10 dankcushions

Also - are there any cases where the enable hotkey alone should do something within retroarch ? I guess another workaround could be only to consider a hotkey being pressed if other keys are pressed with the enable hotkeys key, so pressing enable hotkey alone would just get sent to the core. (Just ideas without having studied any code etc)

joolswills avatar Oct 18 '15 05:10 joolswills

I think the return statement needs to be false for a few milliseconds. If it's false always it might fix our problem, but possibly with some side effects.

ugh... just a fyi, doing something for X amount of time is just ugly and I don't see that being merged anytime.

Also, what if the game needs more than X as the time to register that particular input? Not scalable at all.

andres-asm avatar Oct 18 '15 05:10 andres-asm

I was just floating some ideas. jools' suggestion seems more viable.

I've noticed the issue affects the pcsx core also - the select button is used in King's field 2 as a quick item select, which doesn't work if it's also the hotkey.

dankcushions avatar Oct 18 '15 21:10 dankcushions

ok, so i've tested this - always returning false from the above check_block_hotkey function resolves the issue. obviously this is a hack! the predictable side-effect is that whatever button combo you press along with your hotkey is not blocked. eg, if you do a load state (for me this is select + L-bumper), you will load the state and then trigger whatever the the L-bumper triggers. I believe this would normally be blocked by the check_block_hotkey function.

i want to try @joolswills idea, but it's beyond my c experience (zero!). we need to return false if the hotkey is the only button currently pressed. I'm not sure how to poll the currently pressed key. i want something like:

return (use_hotkey_enable && enable_hotkey && !(OnlyKeyPressed==Hotkey))

i'll carry on playing around but any suggestions welcome :)

dankcushions avatar Oct 20 '15 17:10 dankcushions

In fact, this affects all cores. Most NES games use the select key (e.g. bubble bobble), SNES also (Young merlin, select key is for inventory, Alien3 - select is change weapon and so on).

Please reopen that issue and fix this, it's very annoying you can't use all the keys AND hotkeys :(

The only workaround i can currently think of is handling hotkeys with an addition program like pinnacle game profiler so both the select key works and the hotkeys work as intended, but this should work out of the box.

SimplyLiz avatar Oct 31 '15 08:10 SimplyLiz