Simultaneous button presses

Post Reply
Skye
Posts: 2
Joined: Tue Jul 17, 2012 1:05 pm

Simultaneous button presses

Post by Skye » Wed Jul 18, 2012 12:35 am

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?

Dwedit
Posts: 43
Joined: Sun Jan 06, 2008 4:06 am

Re: Simultaneous button presses

Post by Dwedit » Thu Jul 19, 2012 9:27 pm

keysDown() tells you what keys have *changed state* from not-pressed to pressed.
keysHeld() tells you what keys are currently in a pressed state.

elhobbs
Posts: 358
Joined: Thu Jul 02, 2009 1:19 pm

Re: Simultaneous button presses

Post by elhobbs » Fri Jul 20, 2012 12:33 am

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).

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests