Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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?

  • 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 by somewhatOfACoder

  • 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.

  • 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?

  • 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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.