MinecraftForge/MinecraftForge — pull request #1016 by BalthezarOi (2014-03-28 00:13:45+00:00)
Title: New Keyboard Handler

I thought it would be a good idea to make a handler that can resolve conflicting keybindings.

The problem is that when multiple mods register their keybindings, conflicts occur as keybindings simply conflict or there are too many for the player's keyboard. For example, a player loads 126 mods from the Horizons mod pack in the FTB launcher, but there are mods who register 3-5 keybindings so that the client now how 126+ keybindings registered to the client. Some mods have taken to naming their keybinding's value to key 100 and leaving it to the player to change the keybindings to fix the conflicts. In the end, players have to pick which hot keys to keep and to drop others. Consequently, some mods have their keybindings ignored.

The idea is to create a handler, where a mod registers a Keyboard Switch with the client, and adds their keybindings to it. When a global hot key is pressed, the handler rotates the registered keyboards, and the goal is achieved. When the keyboards rotate, any keybindings on the client, and that are registered to a keyboard switch, are purged and keybindings of the next keyboard switch are added/registered to the client to be used by the player. Minecraft still retains its default keybindings, the only keybindings changed are ones that are added by mods.

The process to change keybindings around is a little difficult, though. I came up with this idea after the 1.7 update, and I haven't been able to look at the source code for how Minecraft registers keybindings. I tried editing the game settings of the client, since it contains an array of keybindings, but editing the array doesn't work. I posted this so that we can discuss how to register/deregister keybindings and hopefully implement this idea into Miencraft Forge.

In the code written below, I have switchKeyboards() called after the player presses both the left and right shift key and the tab key. The handler assigns the variable "activeKeyboard" the next keyboard switch in the list of registered keyboard switches. The method onKeyboardSwitch(KeyboardSwitch keyboardSwitch) is called and this is where keybindings are registered and deregistered to account for differences in the current keybindings and the keybindings in the keyboardSwitch.