diff --git a/config.def.h b/config.def.h index 678928e241..dcc7267d37 100644 --- a/config.def.h +++ b/config.def.h @@ -390,6 +390,7 @@ static const struct retro_keybind retro_keybinds_1[] = { { true, RARCH_MUTE, RETROK_F9, NO_BTN, AXIS_NONE }, { true, RARCH_NETPLAY_FLIP, RETROK_i, NO_BTN, AXIS_NONE }, { true, RARCH_SLOWMOTION, RETROK_e, NO_BTN, AXIS_NONE }, + { true, RARCH_ENABLE_HOTKEY, RETROK_UNKNOWN, NO_BTN, AXIS_NONE }, }; // Player 2-5 diff --git a/driver.h b/driver.h index 74563cb0ec..6f9d0a85f5 100644 --- a/driver.h +++ b/driver.h @@ -85,6 +85,7 @@ enum // RetroArch specific bind IDs. RARCH_MUTE, RARCH_NETPLAY_FLIP, RARCH_SLOWMOTION, + RARCH_ENABLE_HOTKEY, #ifdef RARCH_CONSOLE RARCH_CHEAT_INPUT, @@ -235,6 +236,7 @@ typedef struct driver rarch_cmd_t *command; #endif bool stdin_claimed; + bool block_hotkey; // Opaque handles to currently running window. // Used by e.g. input drivers which bind to a window. @@ -337,6 +339,9 @@ extern const input_driver_t input_null; static inline bool input_key_pressed_func(int key) { + if (driver.block_hotkey) + return false; + bool ret = driver.input->key_pressed(driver.input_data, key); #ifdef HAVE_COMMAND if (!ret && driver.command) diff --git a/retroarch.c b/retroarch.c index 470f7e7deb..65bc6a1d24 100644 --- a/retroarch.c +++ b/retroarch.c @@ -2417,8 +2417,23 @@ static void check_netplay_flip(void) } #endif +static void check_block_hotkey(void) +{ + driver.block_hotkey = false; + + // If we haven't bound anything to this, + // always allow hotkeys. + static const struct retro_keybind *bind = &g_settings.input.binds[0][RARCH_ENABLE_HOTKEY]; + if (bind->key == RETROK_UNKNOWN && bind->joykey == NO_BTN && bind->joyaxis == AXIS_NONE) + return; + + driver.block_hotkey = !input_key_pressed_func(RARCH_ENABLE_HOTKEY); +} + static void do_state_checks(void) { + check_block_hotkey(); + #if defined(HAVE_SCREENSHOTS) && !defined(_XBOX) check_screenshot(); #endif diff --git a/retroarch.cfg b/retroarch.cfg index 9ee740f226..9a554fd58a 100644 --- a/retroarch.cfg +++ b/retroarch.cfg @@ -342,6 +342,16 @@ # Hold for slowmotion. # input_slowmotion = e +# Enable other hotkeys. +# If this hotkey is bound to either keyboard, joybutton or joyaxis, +# all other hotkeys will be disabled unless this hotkey is also held at the same time. +# This is useful for RETRO_KEYBOARD centric implementations +# which query a large area of the keyboard, where it is not desirable +# that hotkeys get in the way. + +# Alternatively, all hotkeys for keyboard could be disabled by the user. +# input_enable_hotkey = + #### Misc # Enable rewinding. This will take a performance hit when playing, so it is disabled by default. diff --git a/settings.c b/settings.c index fc2095136c..7ae6b165db 100644 --- a/settings.c +++ b/settings.c @@ -669,6 +669,7 @@ static const struct bind_map bind_maps[MAX_PLAYERS][RARCH_BIND_LIST_END_NULL] = DECLARE_BIND(audio_mute, RARCH_MUTE), DECLARE_BIND(netplay_flip_players, RARCH_NETPLAY_FLIP), DECLARE_BIND(slowmotion, RARCH_SLOWMOTION), + DECLARE_BIND(enable_hotkey, RARCH_ENABLE_HOTKEY), }, { DECL_PLAYER(2) }, @@ -686,8 +687,6 @@ struct key_map int key; }; -// Edit: Not portable to different input systems atm. Might move this map into the driver itself or something. -// However, this should map nicely over to other systems aswell since the definition are mostly the same anyways. static const struct key_map sk_map[] = { { "left", RETROK_LEFT }, { "right", RETROK_RIGHT },