Jump to content

Detecting a Key Press?


TLHPoE

Recommended Posts

I just made a TickHandler and registered it. Not sure if detecting a key press is supposed to be placed inside a TickHandler, hopefully it's the right way.

 

My TickHandler:

 

 

package deathman12e3.legendaryutilities;

import java.util.EnumSet;
import org.lwjgl.input.Keyboard;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;

public class TickHandler implements ITickHandler
{

@Override
public void tickStart(EnumSet<TickType> type, Object... tickData)
{

	if(Keyboard.isKeyDown(Keyboard.KEY_R))
	{

		System.out.println("HIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII");

	}

}

@Override
public void tickEnd(EnumSet<TickType> type, Object... tickData)
{



}

@Override
public EnumSet<TickType> ticks()
{

	return null;

}

@Override
public String getLabel()
{

	return null;

}

}

 

 

 

My problem is that it never prints anything.

Kain

Link to comment
Share on other sites

why would you need a packet handler ? its a key press

 

example:

import java.util.EnumSet;

import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;

import org.lwjgl.input.Keyboard;

import cpw.mods.fml.client.registry.KeyBindingRegistry.KeyHandler;
import cpw.mods.fml.common.TickType;

public class HBKeyHandler extends KeyHandler {

public HBKeyHandler() {
	super(new KeyBinding[]{new KeyBinding("configure health bar", Keyboard.KEY_C)}, new boolean[]{false});
}

@Override
public String getLabel() {
	return "hbkh";
}

@Override
public void keyDown(EnumSet<TickType> types, KeyBinding kb,
		boolean tickEnd, boolean isRepeat) {
	if(Minecraft.getMinecraft().inGameHasFocus){
		Minecraft.getMinecraft().thePlayer.openGui(MainMod.instance, 0, Minecraft.getMinecraft().theWorld, 0, 0, 0);
	}
}

@Override
public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd) {

}

@Override
public EnumSet<TickType> ticks() {
	return null;
}

}

also, your TickHandler is not working because you are not returning null in "public EnumSet<TickType> ticks()"

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

Nah, I'll just stick with a TickHandler. I think I'll need it later in a little bit.

*hydroflame goes suspicisous mode.... hmmmm*

 

anyway

hum you are returning null

 

@Override
public EnumSet<TickType> ticks(){
	return null;
}

and you should be returning something :

@Override
public EnumSet<TickType> ticks() {
	return EnumSet.of(TickType.PLAYER);
}

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

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.