Skip to content

Allow modifiers for keybindings - #173

Open
jakobhellermann wants to merge 14 commits into
hk-speedrunning:mainfrom
jakobhellermann:keybinding-modifiers
Open

jakobhellermann wants to merge 14 commits into
hk-speedrunning:mainfrom
jakobhellermann:keybinding-modifiers

Conversation

@jakobhellermann

@jakobhellermann jakobhellermann commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Reworks the keybinding system around a Binding type containing modifier flags and the main binding.
Deserialization should stay backwards compatible.

I also refactored the rebinding logic in GUIController to not rely on the implicit KeyCode.None means "is currently rebinding" state, and instead store a rebindTarget action name for that. Let me know what you think about that, I can implement modifiers without making that change if you don't want it.

Keybindings in the settings file look like this: Control+Shift+Alt+Meta+X.

Modifiers don't distinguish between the left and the right variant, so LCtrl+X and RCtrl+X both perform a Control + X keybind. If you bind a modifier key alone it will be the specific key (as was the case previously), stored as Binding { Modifiers = None, Key = KeyCode.LeftControl }.

Also I've made the enum parsing case insensitive, in case someone edits their config to e.g. control+A by hand.

The meta key handling has to be tested on windows and linux. On mac, pressing the left command key apparently emits both LeftMeta and LeftWindows, so I added LeftWindows and RightWindows to the ignored key list.

part of #170

This allows ConfigManager to use its keybinding UI instead of a text
input.
@SpaceMonkeyy86 SpaceMonkeyy86 linked an issue Sep 9, 2026 that may be closed by this pull request

@SpaceMonkeyy86 SpaceMonkeyy86 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks great, just a few notes. Thanks!

Comment thread Binding.cs Outdated
Comment thread Binding.cs Outdated
Comment thread Modifier.cs Outdated
Comment thread Modifier.cs
}
}

internal static Modifier Held() =>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is not actually an extension method. IMO it would be better to put this in Modifier instead, along with the other methods in this class that aren't extension methods. Maybe rename to CurrentlyHeld to make it more clear that it reads Unity input

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think you can do that in c#, put methods on enums.

Comment thread GUIController.cs
Comment thread Settings.cs
private static void AddConfigEntryKeybind(ConfigFile config, string bindName, string displayName, Binding defaultBinding, string description)
{
// KeyboardShortcut instead of Binding, so that ConfigManager knows how to handle it
ConfigEntry<KeyboardShortcut> entry = config.Bind("General", displayName, ToShortcut(defaultBinding), description);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ModMenu won't be able to display this since it's a KeyboardShortcut. Just using a KeyCode instead should be fine, this option is really just for unbricking your settings.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What should the key code be if you bind it to a modifier shortcut? Just the main key?
I'd like to use the same mechanism for the command palette shortcut which will definitely have a modifier by default.

I think I would prefer adding KeyboardShortcut into ModList (useful for other mods as well) and keeping this as is.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

More flexible keybinds

2 participants