Original Post
🔒 Locked
[java] KeyListners for a Multiplayer game
Advertisement
you need to make your own key handler (I know... sounds scary, but it's not).
It needs to do the following:
public class MyKeyHandler implements KeyListener
{
boolean pressed[256]; //assuming a standard char set for now
public void keyPressed(KeyEvent e)
{
pressed[e.getKeyCode] = true;
}
public void keyReleased(KeyEvent e)
{
pressed[256] = false;
}
public void CheckKeys()
{
if(pressed[])
{
//add your code here
}
if(pressed[])
{
//add your code here
}
//and so on.
}
}
I'm assuming you have a thread running to update your screen on even intervals. In the thread's Run loop, call MyKeyHandler.CheckKeys().
Does this help at all?
It needs to do the following:
public class MyKeyHandler implements KeyListener
{
boolean pressed[256]; //assuming a standard char set for now
public void keyPressed(KeyEvent e)
{
pressed[e.getKeyCode] = true;
}
public void keyReleased(KeyEvent e)
{
pressed[256] = false;
}
public void CheckKeys()
{
if(pressed[
{
//add your code here
}
if(pressed[
{
//add your code here
}
//and so on.
}
}
I'm assuming you have a thread running to update your screen on even intervals. In the thread's Run loop, call MyKeyHandler.CheckKeys().
Does this help at all?
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement