Skip to content

Instantly share code, notes, and snippets.

@theoparis
Created September 10, 2019 01:02
Show Gist options
  • Save theoparis/720e19d90a19040b13c7658a43378658 to your computer and use it in GitHub Desktop.
Save theoparis/720e19d90a19040b13c7658a43378658 to your computer and use it in GitHub Desktop.
custom keybind help
package me.creepinson.mod.client;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import org.lwjgl.input.Keyboard;
public class Keybinds
{
public static KeyBinding switch;
public static void register()
{
switch = new KeyBinding("Switch Keybinding", Keyboard.KEY_G, "categories.switch");
ClientRegistry.registerKeyBinding(switch);
MinecraftForge.EVENT_BUS.register(new KeyInputHandler());
}
public static class KeyInputHandler {
@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent event) {
if(Keybinds.switch.isPressed()){
// do something when the keybind is pressed
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment