Java 机器人类与锻造键合
我所要做的就是做一个锻造模组,当我按O时,它会按F3 这是我拥有的2个类文件 KeyBindings.javaJava 机器人类与锻造键合,java,minecraft-forge,Java,Minecraft Forge,我所要做的就是做一个锻造模组,当我按O时,它会按F3 这是我拥有的2个类文件 KeyBindings.java package com.example.examplemod; import cpw.mods.fml.client.registry.ClientRegistry; import net.minecraft.client.settings.KeyBinding; public class KeyBindings { // Declare two KeyBindings,
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键时,不会发生任何事情但这与forge无关,我想如果我使用此代码,我将无法在聊天中写入O字母。您是否在事件总线中注册了KeyInputHandler文件?