MegabonkInput
A library to enable easy and reliable hotkeys on keyboard and gamepad for Windows.
| Last updated | 3 weeks ago |
| Total downloads | 181 |
| Total rating | 0 |
| Categories | Libraries |
| Dependency string | JustaMea-MegabonkInput-1.0.0 |
| Dependants | 0 other packages depend on this package |
This mod requires the following mods to function
BepInEx-BepInExPack_IL2CPP
BepInEx pack for IL2CPP x64 Unity games. Preconfigured and ready to use.
Preferred version: 6.0.733README
What?
This is a library mod that hooks all window messages sent to the game window, allowing reliable input processing and the potential for input blocking and acting on messages such as losing and gaining focus. It doesn't add any functionality to the game by itself, but rather exposes a single constructor on the class "Keybind" and properties to control the keybinds behaviour during runtime.
Why?
I arbitrarily decided I wanted keyboard hotkeys. I spent 3 minutes learning it was possible, 30 minutes failing to find a reference to normal input systems in Megabonk, 3 hours researching Rewired and how I might hook it at runtime, and 30 hours writing this alternative, in that order. On one hand I expect theres an easier way like importing a unity dll or hooking a Rewired method I missed, but on the other this one is flexible and really easy to use. It also brings me one step closer to a Dear ImGui Injector.
How?
You just need to
- Include MegabonkInput.dll in your project
- Integrate the MegabonkInput.Keybind type into your code following the example below
- Decorate your BasePlugin with [BepInDependency("MegabonkInput")]
- In your manifest.josn add a dependancy to this mod
Creating a Keybind is as easy as [BepInDependency("MegabonkInput")] [BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)] public class Plugin : BasePlugin { internal static new ManualLogSource Log; private Keybind myBind;
public override void Load()
{
// Plugin startup logic
Log = base.Log;
Log.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} is loaded!");
// Just instantiating a Keybind sets it up to be active immediatly, no additional method calls needed
// There are three layers of input, by passing "InputLayer.Game | InputLayer.GameUI" this binding will activate when the player has control of a character and in in-game menus, but not in external tools like configurators or trainers
myBind = new Keybind(VirtualKey.VK_DELETE, PressType.WM_KEYDOWN, ExampleAction, InputLayer.Game | InputLayer.GameUI);
}
// This method will be activated each time the Keybinds key is pressed
private void ExampleAction() {
Log.LogInfo($"Keybind was pressed -> {myBind.Key}");
// This keybind is self editing!
if (myBind.Key == VirtualKey.VK_DELETE) {
myBind.Key = VirtualKey.VK_END;
} else {
myBind.Key = VirtualKey.VK_DELETE;
}
}
}
Who?
Not only is it astoundingly easy to use, but it was also really easy to write. Most of the hard bits came from https://github.com/xiaoxiao921/DearImGuiInjection Shoutouts to all of the modders who have touched that source code. It should be easy to expand the functionality to support mouse events and window focusing just as examples, they're all just messages already passing through the mod's handler, so if you have a particular need let me know. -Rivinwin