gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > How to use key combination?

#141806 - viko - Sun Sep 30, 2007 10:35 am

If I want to press L button, it is easy as below,
Code:

   int keysPressed, keysReleased, keysDownNonRepeat;
   while(1)
   {
      swiWaitForVBlank();
      scanKeys();
      
      keysDownNonRepeat = keysDown();
      keysPressed = keysDownRepeat();
      keysReleased = keysUp();
      
      if ( keysPressed & KEY_L ) {
         iprintf("L is pressed");
      }

      
      
   }


How about if I want to press "L+Y"? or even more key combination?

#141807 - Peter - Sun Sep 30, 2007 10:39 am

viko wrote:

How about if I want to press "L+Y"? or even more key combination?


Code:

if ( (keysPressed & (KEY_L | KEY_Y)) == (KEY_L | KEY_Y) )
  iprintf("L+Y is pressed");

_________________
Kind Regards,
Peter

#141808 - melw - Sun Sep 30, 2007 10:57 am

Or you might want to use keysHeld() as pressing two keys exactly at the same time is very hard:

Code:
int held = keysHeld();
if( (held & (KEY_L | KEY_Y)) == (KEY_L | KEY_Y))
  printf("L + Y held\n");

#141809 - viko - Sun Sep 30, 2007 11:36 am

Thx for the kindly quick answer, it helps a lot.

#141823 - keldon - Sun Sep 30, 2007 1:56 pm

melw wrote:
Or you might want to use keysHeld() as pressing two keys exactly at the same time is very hard:

Code:
int held = keysHeld();
if( (held & (KEY_L | KEY_Y)) == (KEY_L | KEY_Y))
  printf("L + Y held\n");

Ditto!