You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
1.1 KiB
86 lines
1.1 KiB
11 years ago
|
package mightypork.rogue.input.events;
|
||
|
|
||
|
|
||
|
import org.lwjgl.input.Keyboard;
|
||
|
|
||
|
import mightypork.utils.patterns.subscription.Handleable;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* A keyboard event
|
||
|
*
|
||
|
* @author MightyPork
|
||
|
*/
|
||
|
public class KeyboardEvent implements Handleable<KeyboardEvent.Listener> {
|
||
|
|
||
|
private int key;
|
||
|
private boolean down;
|
||
|
private char c;
|
||
|
|
||
|
|
||
|
public KeyboardEvent(int key, char c, boolean down) {
|
||
|
this.key = key;
|
||
|
this.c = c;
|
||
|
this.down = down;
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @return key code (see {@link org.lwjgl.input.Keyboard})
|
||
|
*/
|
||
|
public int getKey()
|
||
|
{
|
||
|
return key;
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @return true if key was just pressed
|
||
|
*/
|
||
|
public boolean isDown()
|
||
|
{
|
||
|
return down;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @return true if key was just released
|
||
|
*/
|
||
|
public boolean isUp()
|
||
|
{
|
||
|
return !down;
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @return event character (if any)
|
||
|
*/
|
||
|
public char getChar()
|
||
|
{
|
||
|
return c;
|
||
|
}
|
||
|
|
||
|
|
||
|
@Override
|
||
|
public void handleBy(Listener keh)
|
||
|
{
|
||
|
keh.receive(this);
|
||
|
}
|
||
|
|
||
|
public interface Listener {
|
||
|
|
||
|
/**
|
||
|
* Handle an event
|
||
|
*
|
||
|
* @param event event
|
||
|
*/
|
||
|
public void receive(KeyboardEvent event);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String toString()
|
||
|
{
|
||
|
return Keyboard.getKeyName(key)+":"+(down?"DOWN":"UP");
|
||
|
}
|
||
|
|
||
|
}
|