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 > Are KEY_LEFT and KEY_RIGHT working?

#168539 - sverx - Mon May 04, 2009 12:14 pm

Hi! I've got that simple piece of code that doesn't work as expected both with no$gba and a real NDS Lite... it swaps screens only if I press the X button, nothing happens if I use the LEFT or RIGHT keys instead.

I'm using the latest devkit and libnds, AFAIK...

Code:
if (keysHeld() & (KEY_LEFT|KEY_RIGHT|KEY_X)) { 
  lcdMainOnBottom();
} else {
  lcdMainOnTop();
}


Any ideas? I've been searching the forum for this with no luck...
Thanks!




?

#168540 - elhobbs - Mon May 04, 2009 1:18 pm

search for keysHeld

main points - make sure you do not call irqInit, scanKeys needs to be called at lease twice for keysHeld to return a value. if you are trying to detect if a key is held at startup then call scanKeys twice in a row.

#168543 - sverx - Mon May 04, 2009 2:26 pm

elhobbs wrote:
search for keysHeld

main points - make sure you do not call irqInit, scanKeys needs to be called at lease twice for keysHeld to return a value. if you are trying to detect if a key is held at startup then call scanKeys twice in a row.


No luck... I've read other topics about other type of problems, nothing related to what I'm experiencing... I call that keysHeld() in a code like this

Code:
while(1) {
  scanKeys();
  // here the code I wrote in my previous post
  swiWaitForVBlank();
}


and it's OK when I hold X, not OK when I hold LEFT or RIGHT instead... and I do not have any irqInit() in my code... other suggestions?


?

#168544 - gauauu - Mon May 04, 2009 3:03 pm

Is the value returned from keysHeld changed when you press left and right? The problem is either in keysHeld or in your KEY_LEFT/KEY_RIGHT constants, so it shouldn't be too hard to narrow down which it is.

Do you have a text system set up? If so, loop and repeatedly dump out the value of keysHeld and check it against what the specs tell you. You should be able to find out pretty fast where the issue is. (Now finding out WHY might be trickier)

#168546 - sverx - Mon May 04, 2009 3:26 pm

gauauu wrote:
Is the value returned from keysHeld changed when you press left and right?


Good suggestion. I made a test and... yes, it changes. 0x200 and 0x100 respectively. So it's funny, because I'm using the... oh-oh-oh ... ok, ok, I made a big confusion: I meant to use KEY_R and KEY_L (shoulder buttons), not KEY_RIGHT and KEY_LEFT (on "cross" button).

Keep this post for future generations ;)

Thanks! :)