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

Hello,

 

I just want to send a message to a player if a key is pressed, but, when I press the key nothing happends.

 

My Event class:

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiChat;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.util.ChatComponentText;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class KeyPressEvents {

@SideOnly(Side.CLIENT)
@SubscribeEvent(receiveCanceled=true)
public void onKeyInput( KeyInputEvent event ) {
	System.out.println( "called" );
	if( Minecraft.getMinecraft().gameSettings.keyBindInventory.isPressed() )
		if (!FMLClientHandler.instance().isGUIOpen(GuiChat.class)) 
			Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( "Pressed" ) );
}
}

 

I registered it at the FMLCommonHandler's EventBus

FMLCommonHandler.instance().bus().register( new KeyPressEvents() );

 

The

System.out.println( "called" );

is never showen

 

Sorry if there are mistakes in my english

Where do you register your event?

KeyInputEvent is fired on client side, so it should be registered in your client proxy on init.

 

Also, it would probably be a good idea to mark KeyPressEvents class as Client-Side only if you are using it only for KeyInput handling.

 

As far as I know, there is no problem with your code. Tested it in 1.7.10 and worked fine.

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.