Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ControlsHandling implements KeyListener, MouseListener, MouseMotionListener
- {
- boolean keys[] = new boolean[256];
- int triggered = 0;
- /*
- //ignore this
- boolean mouse[] = new boolean[4];
- boolean enterd, exited, dragging, moving;
- int clickx, clicky;
- int pressx, pressy;
- int releasex, releasey;
- int enterx, entery;
- int dragx, dragy;
- int exitx, exity;
- int movex, movey;
- */
- /**
- * Constructor for objects of class ControlsHandling
- */
- public ControlsHandling(Component c)
- {
- c.addKeyListener(this);
- c.addMouseListener(this);
- c.addMouseMotionListener(this);
- }
- //Detecting KeyBoard input
- /**
- * Called when a key is pressed while the component is focused
- * @param e KeyEvent sent by the component
- */
- public void keyPressed(KeyEvent e)
- {
- if (e.getKeyCode() > 0 && e.getKeyCode() < 256)
- {
- keys[e.getKeyCode()] = true;
- }
- }
- /**
- * Called when a key is released while the component is focused
- * @param e KeyEvent sent by the component
- */
- public void keyReleased(KeyEvent e)
- {
- if (e.getKeyCode() > 0 && e.getKeyCode() < 256)
- {
- keys[e.getKeyCode()] = false;
- }
- }
- /**
- * Not used yet :)
- */
- public void keyTyped(KeyEvent e){}
- //Keyboard Functions for external use
- /**
- * Checks whether a specific key is down
- * @param keyCode The key to check
- * @return Whether the key is pressed or not
- */
- public boolean isKeyDown(int keyCode)
- {
- if (keyCode > 0 && keyCode < 256)
- {
- return keys[keyCode];
- }
- return false;
- }
- //This function isn't working like I want it to.
- public boolean isTriggered(int keyCode)
- {
- if (keyCode > 0 && keyCode < 256)
- {
- if(triggered < 1)
- {
- triggered++;
- return keys[keyCode];
- }
- }
- triggered = 0;
- return false;
- }
- //A lot more here I'm not concerned about yet
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement