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 > Is keysSetRepeat() and keysDownRepeat() working? [nvm]

#167287 - DiscoStew - Sun Mar 08, 2009 7:57 am

I don't know if I'm doing this the wrong way, but I have my code similar to this...

Code:
...
...
keysSetRepeat( 20, 10 );
...
while( 1 )
{
   scanKeys();
   ...
   ...
   if( keysDownRepeat() & KEY_UP )
      ...
   else if( keysDownRepeat() & KEY_DOWN )
      ...
   ...
   ...
   swiWaitForVBlank();
}


What I believe I should be expecting is that at the moment I hold down either Up or Down, it triggers once, then wait for 20 scanKeys() cycles before it starts repeating, and it repeats once every 10 scanKeys() cycles, correct?

Well, with trying to use it, I get nothing. No activity from keysDownRepeat(). Anyone else tried using them?


EDIT:

Please delete......it seemed that doing direct ANDing didn't work, but storing the result, and ANDing that does work.
_________________
DS - It's all about DiscoStew

#167334 - albinofrenchy - Mon Mar 09, 2009 11:11 am

Don't delete, its informative if someone else has the same issue :)

Here is why btw, check out libnds source file keys.c:

Code:

//------------------------------------------------------------------------------
uint32 keysDownRepeat(void) {
//------------------------------------------------------------------------------
   uint32 tmp = keysrepeat;

    keysrepeat = 0;

    return tmp;
}


You could probably make the case that this is a bug; that keysrepeat shouldn't be zeroed out until scanKeys is called again.