Skip to content

WIP: SDL Keyboard and Mouse support#296

Closed
AL2009man wants to merge 42 commits into
GooberRF:masterfrom
AL2009man:SDL-Mouse
Closed

WIP: SDL Keyboard and Mouse support#296
AL2009man wants to merge 42 commits into
GooberRF:masterfrom
AL2009man:SDL-Mouse

Conversation

@AL2009man

@AL2009man AL2009man commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

This commit repurposes DirectInput mode with a Input Handling system, allowing introduction to SDL's Keyboard and Mouse Input systems alongside minor (accidental) improvements to the Windowing Management.

SDL also allow us to adds support for additional keybinds, including Mouse 3/4 buttons.

For those who prefer either the Legacy handling and/or it's DirectInput Mouse mode: you can always swap it back. (Note: SDL Cursor is always in use for Main Menu navigation regardless of Input handles)

optionally: this PR is best merged alongside #295 for the smoothest transition

@AL2009man AL2009man marked this pull request as draft March 14, 2026 23:19
@AL2009man AL2009man marked this pull request as ready for review March 14, 2026 23:28
@GooberRF

Copy link
Copy Markdown
Owner

Could you explain a bit about the benefits of this approach vs. existing DirectInput?

I am most certainly not opposed to improvements, however unless I am mistaken, this would this remove the stock software input method in its entirety? That is an approach that certainly comes with drawbacks. For instance, although DirectInput is better in virtually every way, there are still many people who use the stock input method to this day because they're used to and prefer it.

@GooberRF GooberRF requested a review from Copilot March 15, 2026 00:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR replaces the game’s DirectInput-based mouse path with SDL3 mouse input, removing the DirectInput toggle/settings/UI and wiring SDL init/polling into the main OS/game loops.

Changes:

  • Removed DirectInput headers, runtime state, config serialization, and the “DirectInput” UI/console toggle.
  • Added SDL3 initialization/teardown and per-frame SDL mouse polling.
  • Hooked mouse delta retrieval to feed SDL relative motion and enabled SDL relative mouse mode when “keep centered” is active.

Reviewed changes

Copilot reviewed 9 out of 99 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
game_patch/rf/input.h Removes DirectInput includes and DirectInput-related memory refs.
game_patch/os/os.cpp Initializes SDL, polls SDL mouse each frame, and quits SDL on shutdown.
game_patch/misc/ui.cpp Removes DirectInput checkbox and reflows panel controls.
game_patch/misc/alpine_settings.h Removes persisted direct_input setting.
game_patch/misc/alpine_settings.cpp Stops loading/saving the DirectInput config key.
game_patch/main/main.cpp Creates the SDL window wrapper after RF init.
game_patch/input/mouse.cpp Implements SDL relative motion accumulation + hooks into RF mouse delta flow.
game_patch/input/input.h Exposes SDL mouse init/poll functions.
game_patch/CMakeLists.txt Links SDL3 static target and additional Windows system libs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread game_patch/input/mouse.cpp
Comment thread game_patch/os/os.cpp Outdated
Comment thread game_patch/os/os.cpp Outdated
Comment thread game_patch/input/mouse.cpp Outdated
Comment thread game_patch/CMakeLists.txt Outdated
AL2009man added a commit to AL2009man/alpinefaction that referenced this pull request Mar 15, 2026
@AL2009man AL2009man marked this pull request as draft March 15, 2026 03:49
@AL2009man

AL2009man commented Mar 15, 2026

Copy link
Copy Markdown
Contributor Author

Could you explain a bit about the benefits of this approach vs. existing DirectInput?

I am most certainly not opposed to improvements, however unless I am mistaken, this would this remove the stock software input method in its entirety? That is an approach that certainly comes with drawbacks. For instance, although DirectInput is better in virtually every way, there are still many people who use the stock input method to this day because they're used to and prefer it.

basically: consolidation. no need for two different Input APIs when you can have one that does it for you, and more future-proof.

SDL is meant to be a hardware abstraction layer that does alot of things, it does Inputs so it'll use the best Input API available for the OS in question, and this applies to game controllers. as far as I can tell: SDL Mouse on Windows will use Raw Input (or Win32 WM_MOUSE?). As far as I can tell: overall Mouse Input performance on my own trackball should behave the same regardless.

that being said, I've restored the ability to switch to stock input.

@AL2009man AL2009man changed the title Replace DirectInput's Mouse with SDL Replace DirectInput's Mouse and Keyboard with SDL Mar 16, 2026
upgrade portions of the keyboard handler with SDL.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates core mouse + keyboard input handling from DirectInput/Win32 message processing to an SDL3-driven polling approach, and adds SDL3 as a vendored FetchContent dependency (plus a new UI/config toggle to switch SDL mouse vs “stock” mouse input).

Changes:

  • Add SDL3 (FetchContent) to the build and link AlpineFaction against SDL3::SDL3-static, plus required Win32 libs for static SDL.
  • Introduce a central SDL event pump (sdl_input_poll) and wire it into the OS poll loop; implement SDL-based mouse delta and keyboard event feeding into RF.
  • Replace the old “DirectInput” config/UI toggle with an “SDL mouse” toggle and persist it as SDLMouse in the config.

Reviewed changes

Copilot reviewed 12 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
vendor/sdl/LICENSE.txt Adds SDL license text for the new SDL dependency.
vendor/sdl/CMakeLists.txt FetchContent setup to build SDL3 from source (static).
vendor/CMakeLists.txt Includes the new vendor/sdl subdirectory.
resources/licensing-info.txt Adds SDL license block to licensing info aggregation.
game_patch/rf/input.h Removes DirectInput-specific globals/includes from RF input header.
game_patch/os/os.cpp Initializes SDL, polls SDL input during OS polling, and switches cursor show/hide to SDL helpers.
game_patch/misc/ui.cpp Renames the options checkbox from DirectInput to SDL mouse and hooks toggle to SDL mouse enable/disable.
game_patch/misc/alpine_settings.h Replaces direct_input config flag with sdl_mouse.
game_patch/misc/alpine_settings.cpp Loads/saves the new SDLMouse config key instead of DirectInput.
game_patch/main/main.cpp Creates the SDL window wrapper after RF init via mouse_init_sdl_window().
game_patch/input/mouse.cpp Implements SDL mouse deltas + relative mode integration; provides toggle and hooks.
game_patch/input/key.cpp Implements SDL keyboard polling and replaces Win32 keyboard message forwarding with SDL-fed events.
game_patch/input/input.h Declares SDL input polling and initialization helpers.
game_patch/input/input.cpp Adds central SDL event pumping function used by OS poll hook.
game_patch/CMakeLists.txt Adds input/input.cpp and links SDL3 static (plus extra Win32 libs).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread game_patch/os/os.cpp Outdated
Comment thread game_patch/misc/alpine_settings.cpp Outdated
@AL2009man AL2009man marked this pull request as ready for review March 16, 2026 16:47
@AL2009man

AL2009man commented Mar 16, 2026

Copy link
Copy Markdown
Contributor Author

SDL Keyboard has been officially added into it. with that, i felt that it's complete enough for a full review.

that being said, i did have to do last-minute timer fixes but i'm not too sure if the master branch is going to break it due to side effects

the camera will no longer speen when disabling SDL Mouse
@AL2009man AL2009man marked this pull request as draft March 26, 2026 11:13
@AL2009man AL2009man changed the title adds SDL Keyboard and Mouse WIP: SDL Keyboard and Mouse Apr 16, 2026
@AL2009man AL2009man changed the title WIP: SDL Keyboard and Mouse WIP: SDL Keyboard and Mouse support Apr 16, 2026
AL2009man and others added 4 commits April 17, 2026 23:35
added experimental support for On-Screen Keyboard across all Input Modes. Right now: it only applies if a game detects there's no keyboard attached, or using Steam Deck
AL2009man and others added 6 commits April 27, 2026 22:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 18 changed files in this pull request and generated 4 comments.

Comment thread game_patch/input/input.h
Comment on lines +7 to +13
// Sentinel scan code injected into Input Rebind UI, allowing additional input bindings.
static constexpr int CTRL_REBIND_SENTINEL = 0x58; // KEY_F12

// Extra keyboard scan codes not in RF's original DInput table.
// Placed after CTRL_EXTRA_MOUSE_SCAN (0x75–0x79), before RF extended keys (0x9C+).
static constexpr int CTRL_EXTRA_KEY_SCAN_BASE = 0x7A;
static constexpr int CTRL_EXTRA_KEY_SCAN_COUNT = 14;
Comment thread game_patch/input/key.cpp Outdated
Comment thread game_patch/os/os.cpp
Comment on lines +338 to +350
void os_init_sdl_window()
{
// Deferred after D3D device creation so SDL's hidden helper window does not
// interfere with exclusive fullscreen acquisition.
os_init_sdl_video();

SDL_PropertiesID props = SDL_CreateProperties();
SDL_SetPointerProperty(props, SDL_PROP_WINDOW_CREATE_WIN32_HWND_POINTER, rf::main_wnd);
g_sdl_window = SDL_CreateWindowWithProperties(props);
SDL_DestroyProperties(props);
if (!g_sdl_window) {
xlog::error("SDL_CreateWindowWithProperties failed: {}", SDL_GetError());
return;
Comment thread game_patch/input/key.cpp
Comment on lines +191 to +205
case KEY_RAPOSTRO: return SDL_SCANCODE_APOSTROPHE;
case KEY_LAPOSTRO_DBG: return SDL_SCANCODE_GRAVE;
case KEY_LSHIFT: return SDL_SCANCODE_LSHIFT;
case KEY_SLASH: return SDL_SCANCODE_BACKSLASH;
case KEY_Z: return SDL_SCANCODE_Z;
case KEY_X: return SDL_SCANCODE_X;
case KEY_C: return SDL_SCANCODE_C;
case KEY_V: return SDL_SCANCODE_V;
case KEY_B: return SDL_SCANCODE_B;
case KEY_N: return SDL_SCANCODE_N;
case KEY_M: return SDL_SCANCODE_M;
case KEY_COMMA: return SDL_SCANCODE_COMMA;
case KEY_PERIOD: return SDL_SCANCODE_PERIOD;
case KEY_DIVIDE: return SDL_SCANCODE_SLASH;
case KEY_RSHIFT: return SDL_SCANCODE_RSHIFT;
@AL2009man

Copy link
Copy Markdown
Contributor Author

i will be putting this on hold for the time being due to an issue with how Exclusive Window handles it. Instead: I'll make a separate PR that focus on adding additional mouse input presses and Alt keys.

#374

@AL2009man AL2009man closed this May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants