Page 1 of 1

Simultaneous button presses

Posted: Wed Jul 18, 2012 12:35 am
by Skye
This might be a trivial question but I can't seem to find the answer. I would like to move stuff diagonally, so I want to check for KEY_UP and KEY_RIGHT for example. What I do at the moment is the following:

while(1) loop, lastKey is just a global int

Code: Select all

		scanKeys();
		if(keysDown())
			lastKey = keysDown();
Then I switch

Code: Select all

	switch(lastKey)
	{
	case (KEY_RIGHT): 
              //Code here
So I tried

Code: Select all

	case (KEY_UP | KEY_RIGHT):
but that didn't seem to work as I'm guessing keysDown() only reports the last pressed button. What is the correct way to handle this?

Re: Simultaneous button presses

Posted: Thu Jul 19, 2012 9:27 pm
by Dwedit
keysDown() tells you what keys have *changed state* from not-pressed to pressed.
keysHeld() tells you what keys are currently in a pressed state.

Re: Simultaneous button presses

Posted: Fri Jul 20, 2012 12:33 am
by elhobbs
keysCurrent() will return the current key state independent of scanKeys. it reads directly from the registers for the keys that can be read from the arm9 and the latest polled values from the keys that can only be read from the arm7 (touch,x,y - I think).