机器人类和伪造键绑定

时间:2014-12-13 09:24:19

标签: java minecraft-forge

我想要的是制作一个锻造模式,当我按下

时按下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, 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时,没有任何事情发生

0 个答案:

没有答案