Search in sources :

Example 1 with EventKeyPress

use of dev.hypnotic.event.events.EventKeyPress in project Hypnotic-Client by Hypnotic-Development.

the class KeyboardMixin method onKey.

@Inject(method = "onKey", at = @At("HEAD"), cancellable = true)
public void onKey(long window, int key, int scancode, int action, int modifiers, CallbackInfo info) {
    if (key != GLFW.GLFW_KEY_UNKNOWN) {
        /*
        	 * action == GLFW.GLFW_PRESS is important
        	 * so the module does not toggle twice
        	 */
        KeyUtils.setKeyState(key, action != GLFW.GLFW_RELEASE);
        for (Mod mod : ModuleManager.INSTANCE.modules) {
            if (mod.getKey() == key && action == GLFW.GLFW_PRESS && MinecraftClient.getInstance().currentScreen == null)
                mod.toggle();
        }
        EventKeyPress event = new EventKeyPress(key, scancode, action);
        event.call();
        if (event.isCancelled())
            info.cancel();
        if (client.currentScreen == null && key == KeyUtils.getKey(CommandManager.INSTANCE.getPrefix()) && action == GLFW.GLFW_PRESS)
            client.setScreen(new ChatScreen(""));
    }
}
Also used : ChatScreen(net.minecraft.client.gui.screen.ChatScreen) Mod(dev.hypnotic.module.Mod) EventKeyPress(dev.hypnotic.event.events.EventKeyPress) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

EventKeyPress (dev.hypnotic.event.events.EventKeyPress)1 Mod (dev.hypnotic.module.Mod)1 ChatScreen (net.minecraft.client.gui.screen.ChatScreen)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1