Search in sources :

Example 1 with KeyPressEvent

use of net.wurstclient.events.KeyPressListener.KeyPressEvent in project Wurst-MC-1.12 by Wurst-Imperium.

the class KeybindProcessor method onKeyPress.

public void onKeyPress() {
    if (!WurstClient.INSTANCE.isEnabled())
        return;
    int keyCode = Keyboard.getEventKey();
    if (keyCode == 0 || !Keyboard.getEventKeyState())
        return;
    String keyName = Keyboard.getKeyName(keyCode);
    KeyPressEvent event = new KeyPressEvent(keyCode, keyName);
    WurstClient.INSTANCE.events.fire(event);
    String commands = keybinds.getCommands(keyName);
    if (commands == null)
        return;
    commands = commands.replace(";", "�").replace("��", ";");
    for (String command : commands.split("�")) {
        command = command.trim();
        if (command.startsWith("."))
            cmdProcessor.runCommand(command.substring(1));
        else if (command.contains(" "))
            cmdProcessor.runCommand(command);
        else {
            Mod mod = mods.getModByName(command);
            if (mod != null)
                mod.toggle();
            else
                cmdProcessor.runCommand(command);
        }
    }
}
Also used : Mod(net.wurstclient.features.Mod) KeyPressEvent(net.wurstclient.events.KeyPressListener.KeyPressEvent)

Aggregations

KeyPressEvent (net.wurstclient.events.KeyPressListener.KeyPressEvent)1 Mod (net.wurstclient.features.Mod)1