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 > keysDownRepeat() not working correctly?

#158621 - vuurrobin - Sun Jun 15, 2008 12:15 am

hello everybody

I've just started programming for the NDS, and I'm still trying to figure different things out. one of those things is the different functions for key input. I've made an example program to test it out, but keysDownRepeat() seems to act differently than I expected. if you hold down the A key, it will show its message, but on the next itteration its message dissapears, and after a second or so the message appears and dissapears again.

is this the correct/expected output or is there something wrong with the code or compiler. (it can't be emulator since it acts the same on my NDS)

here is the code:

Code:
#include <nds.h>
#include <stdio.h>
   
int main(void)
{
   consoleDemoInit();
   irqInit();   
   irqEnable(IRQ_VBLANK);

   while (true)
   {
      scanKeys();
      int held = keysHeld();
      int down = keysDown();
      int repeat = keysDownRepeat();
      int up = keysUp();
   
      if (down & KEY_A)
         printf("Key A is pressed again\naaaaaaaaaaaaaaa\naaaaaaaaaaaaaaa\n");
      else if (repeat & KEY_A)
         printf("Key A is repeatedly hold down\n");
      else if (held & KEY_A)
         printf("Key A is pressed\n");
      else if (up & KEY_A)
         printf("Key A is released\naaaaaaaaaa\n");
      else
         printf("Key A isn't pressed\n");

 
      swiWaitForVBlank();
      consoleClear();
   }
   
   return 0;
}


the many "aaaa" are just to make it a bit more clearer to see which message it is.

#158630 - M3d10n - Sun Jun 15, 2008 2:48 am

Sound like it's working exactly like it should: the keys repeat fires at a set time interval (there's a function to change the repeat frequency, but it escapes me). If you want the message on every iteration, use keys held.

The repeat is useful if you want something to to happen every N milliseconds while a key is being held down (like scrolling a list using the D-pad).

#158654 - vuurrobin - Sun Jun 15, 2008 9:56 pm

so I just misunderstood what the function was for.

thanks :)