0

我想要的只是制作一个锻造模组,当我按 O 时按 F3

这是我有 KeyBindings.java 的 2 个类文件

package com.example.examplemod;
import cpw.mods.fml.client.registry.ClientRegistry;
import net.minecraft.client.settings.KeyBinding;

public class KeyBindings {

    // Declare two KeyBindings, ping and pong
    public static KeyBinding ping;

    public static void init() {
        // Define the "ping" binding, with (unlocalized) name "key.ping" and
        // the category with (unlocalized) name "key.categories.mymod" and
        // key code 24 ("O", LWJGL constant: Keyboard.KEY_O)
        ping = new KeyBinding("key.ping", 24, "key.categories.mymod");
        // Register both KeyBindings to the ClientRegistry
        ClientRegistry.registerKeyBinding(ping);
    }

}

KeyInputHandler.java

package com.example.examplemod;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;
import java.awt.Robot;
import java.awt.event.KeyEvent;

public class KeyInputHandler {

    @SubscribeEvent
    public void onKeyInput(InputEvent.KeyInputEvent event) {
        if(KeyBindings.ping.isPressed())
            System.out.println("ping");
        try {
            Robot r = new Robot();
            r.keyPress(KeyEvent.VK_F3);
            r.keyRelease(KeyEvent.VK_F3);
    } catch (Exception e) {
        e.printStackTrace();
}
    }
}

当我进入游戏并按 O 时没有任何反应

4

0 回答 0