Sign in to follow this  
Daggerbot

About menu systems and input...

Recommended Posts

Would it be more practical to handle keyboard presses in the form of events, or just get the state of a given key and have a value containing the previous state in a menu system? For example:
void run()
{
  if( input->getKey( keyMap.up ))
    if( !lastStateUp )
      moveUp();

  if( input->getKey( keyMap.down ))
    if( !lastStateDown )
      moveDown();
}


...or...
void init()
{
  input->addKeyListener( this );
}

void keyPressed( Input* input, int key )
{
  if( key == keyMap.up )
    moveUp();
  else if( key == keyMap.down )
    moveDown();
}
I hope I was clear enough on my question. Any help is appreciated.

Share this post


Link to post
Share on other sites
Personally, I'd take the former since it is simpler. Just a straightforward function that saves old kb state, gets new kb state, then processes keys should be fine. I don't think it makes a huge difference either way though.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this