Jump to content

[1.8] [SOLVED] KeyInputEvent isn't fired


TheCrafter4000

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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