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

Key event handlers.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

Wow really?

InputEvent.KeyInputEvent only is called when key is pressed, but no when key is released.

Its amazing what kind of information you can convey in your opening post, and how a lack thereof doesn't result in useful replies.

 

Here's what I did when I needed key-up and key-down (specifically, a key bound to an existing option).

//client-side event handler
@SubscribeEvent
public void tickStart(TickEvent.ClientTickEvent event) {
	EntityPlayer player = Minecraft.getMinecraft().thePlayer;
	if(player != null) {
		int jumpKey = Minecraft.getMinecraft().gameSettings.keyBindJump.getKeyCode();
		boolean sendPacket = false;
		boolean state = false;
		if(jumpKey >= 0) {
			sendPacket = HazardsEventHandler.instance.setPlayerSwimming(player, Keyboard.isKeyDown(jumpKey));
			state = Keyboard.isKeyDown(jumpKey);
		}
		else {
			jumpKey = Minecraft.getMinecraft().gameSettings.keyBindJump.getKeyCode()+100;
			if(jumpKey >= 0) {
				sendPacket = HazardsEventHandler.instance.setPlayerSwimming(player, Mouse.isButtonDown(jumpKey));
				state = Keyboard.isKeyDown(jumpKey);
			}
		}
		if(sendPacket) {
			PacketBuffer out = new PacketBuffer(Unpooled.buffer());
			out.writeBoolean(state);
			CtoSMessage packet = new CtoSMessage(player.getUniqueID(), out);
			UndergroundBase.networkWrapper.sendToServer(packet);
		}
	}
}

You'll not that there are packets involved.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

I do it like that:

	@SubscribeEvent
public void tickStart(TickEvent.ClientTickEvent event)
{
	EntityPlayer player = Minecraft.getMinecraft().thePlayer;

	if (player != null)
	{
		Entity ent = player.ridingEntity;
		boolean state = false;
		if (ent != null && ent instanceof EntityMyPig)
		{
			state = Keyboard.isKeyDown(ClientKeyHandler.up.getKeyCode()) || Keyboard.isKeyDown(ClientKeyHandler.down.getKeyCode());
			if(!state)
				Main.proxy.channel.sendToServer(PacketHandler.getPacket(1, Side.SERVER));
		}
	}
}

 

And my method isn't called:(

ClientKeyHandler.up.getKeyCode()
ClientKeyHandler.down.getKeyCode()

 

Wut.

 

Actually KeyInputEvent fires for key-releases, but you need 1.7.10 for that (why are you not using that?).

 

I had some issues with that, actually.  And yes, 1.7.10 here.  Do you know if it was a specific Forge version?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

I've been pretty lazy about updating my dev-environment-forge.  I was likely doing a lot of my screwing around with keyboard stuff on 1180 which would, in fact, not have that change. ;)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Guest
This topic is now closed to further replies.

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.