Skip to content

Commit

Permalink
Add a hotkey to bypass emulated keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
bslenul authored and flyinghead committed Dec 7, 2023
1 parent 7cc77b1 commit 9137ff9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/input/gamepad.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ enum DreamcastKey
EMU_BTN_ESCAPE,
EMU_BTN_LOADSTATE,
EMU_BTN_SAVESTATE,
EMU_BTN_BYPASS_KB,

// Real axes
DC_AXIS_TRIGGERS = 0x1000000,
Expand Down
22 changes: 21 additions & 1 deletion core/input/keyboard_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ class KeyboardDevice : public GamepadDevice

void input(u8 keycode, bool pressed, int modifier_keys)
{
const int port = maple_port();

// Checking if we're in-game with an emulated keyboard first,
// then check if the "Bypass Emulated Keyboard" hotkey is held and we're not in GUI,
// if so: send emu hotkeys only and return earlier.
if ((settings.platform.isConsole() && config::MapleMainDevices[port] == MDT_Keyboard)
|| (settings.platform.isArcade() && settings.input.keyboardGame))
{
if (keycode == input_mapper->get_button_code(0, EMU_BTN_BYPASS_KB))
bypass_kb = pressed && !gui_keyboard_captured();

if (bypass_kb)
{
set_maple_port(-1);
gamepad_btn_input(keycode, pressed);
set_maple_port(port);
return;
}
}

// Some OSes (Mac OS) don't distinguish left and right modifier keys so we set them both.
// But not for Alt since Right Alt is used as a special modifier keys on some international
// keyboards.
Expand All @@ -105,7 +125,6 @@ class KeyboardDevice : public GamepadDevice
default:
break;
}
const int port = maple_port();
if (port >= 0 && port < (int)std::size(kb_shift))
kb_shift[port] = _modifier_keys;

Expand Down Expand Up @@ -470,4 +489,5 @@ class KeyboardDevice : public GamepadDevice

int _modifier_keys = 0;
u32 _kb_used = 0;
bool bypass_kb = false;
};
1 change: 1 addition & 0 deletions core/input/mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ button_list[] =
{ DC_BTN_INSERT_CARD, "emulator", "insert_card" },
{ EMU_BTN_LOADSTATE, "emulator", "btn_jump_state" },
{ EMU_BTN_SAVESTATE, "emulator", "btn_quick_save" },
{ EMU_BTN_BYPASS_KB, "emulator", "btn_bypass_kb" },
};

static struct
Expand Down
2 changes: 2 additions & 0 deletions core/rend/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,7 @@ const Mapping dcButtons[] = {
{ EMU_BTN_FFORWARD, "Fast-forward" },
{ EMU_BTN_LOADSTATE, "Load State" },
{ EMU_BTN_SAVESTATE, "Save State" },
{ EMU_BTN_BYPASS_KB, "Bypass Emulated Keyboard" },

{ EMU_BTN_NONE, nullptr }
};
Expand Down Expand Up @@ -883,6 +884,7 @@ const Mapping arcadeButtons[] = {
{ EMU_BTN_FFORWARD, "Fast-forward" },
{ EMU_BTN_LOADSTATE, "Load State" },
{ EMU_BTN_SAVESTATE, "Save State" },
{ EMU_BTN_BYPASS_KB, "Bypass Emulated Keyboard" },

{ EMU_BTN_NONE, nullptr }
};
Expand Down

0 comments on commit 9137ff9

Please sign in to comment.