Posted February 1, 20214 yr I am trying to simulate keyboard and mouse input for a neural network but I can't figure out how to actually get the keys to be pressed. I put the following code into a separate class but when I call the jump method nothing happens. public static void jump() { Minecraft mc = Minecraft.getInstance(); KeyBinding.setKeyBindState(mc.gameSettings.keyBindJump.getKey(), true); KeyBinding.onTick(mc.gameSettings.keyBindJump.getKey()); } The method is indeed being called but the jump keybind isn't changing whatsoever. How do I go about simulating these inputs?
February 2, 20214 yr Author Looking at both KeyboardListener#setupCallbacks and MouseHelper#registerCallbacks, I can see that I need to use the following: // for the keyboard this.onKeyEvent(windowPointer, key, scanCode, action, modifiers); // for the mouse this.mouseButtonCallback(handle1, button, action, modifiers); However I am unsure as to how to get the windowPointer and the handle1. From what I understand, InputMappings#setKeyCallbacks gives the necessary parameters, but calling this again would mean that I would need my own onKeyEvent and mouseButtonCallback methods to handle the input. Do I need to call InputMappings#setKeyCallbacks again or is there a nice way to get the windowPointer and the other parameters? Edited February 2, 20214 yr by somewhatOfACoder
February 2, 20214 yr Author Ok so I changed the method I made to be the following: public static void jump() { Minecraft mc = Minecraft.getInstance(); int jumpKeyCode = mc.gameSettings.keyBindJump.getKey().getKeyCode(); int scanCode = jumpKeyCode; int action = 1; int modifiers = 0; mc.keyboardListener.onKeyEvent(mc.getMainWindow().getHandle(), jumpKeyCode, scanCode, action, modifiers); } However it still doesn't work. The keyCode is fine, but I am not sure about how to get the scanCode. I had a look at KeyboardListener#onKeyEvent and it seems that if the action is 1 then the key will be pressed. I am also not sure about the modifiers because I can't find where it is used.
February 2, 20214 yr Author Ok I am now stumped. I read the input guide and made a callback method for the keyboard which allowed me to get the keycode, scancode, action and modifier of whatever key I typed. However after using these values as parameters for KeyboardListener#onKeyEvent, nothing happened. For example, the space bar has a keycode of 32, a scancode of 57, an action of 1 when pressed and no modifiers. When I put these values directly into KeyboardListener#onKeyEvent nothing happened. Help?
February 2, 20214 yr Author Unforntunately I haven't got it to work. I tried sending two presses as you said, one down then one up, but it didn't work. Do I need to have some sort of delay inbetween? And if so how do I do that
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.