Arduino IRremote.h library

I have a program that is trying to record the a fixed number keys from any tv remote that will then be used to control a POV clock.

Essentially what I am trying to do is this in old school programming.

Writeln("Press up arrow:");
Readkey(m_nUpArrowKey);
Writeln("Press down arrow:");
Readkey(m_nDownArrowKey);

The problem is the damn remote keys are far more sensitive than a keyboard key and they repeat the key code even if you hold down the key for even the briefest of moments. So I am basically reading the same code for the above two different variables.

I cannot for the life of me figure out a way to consume the excess 'key strokes' until the user hits a different key on the remote.

Below is what I have at present but it locks up in side the loop while (results.value == nLastCode).
The other problem I have had is that a key press of the up arrow results in both m_nUpArrowCode and m_nDownArrowCode being filled with the same code from IRRecieve.decode(...).

Those who program the tvs must have the same sort of problem so how the buggery do they make the tv volume, for example, go up with discrete presses of the increase volume button rather than continuously as long as the increase volume button is depressed?

How do I make IRRecieve.decode(...) behave like Readkey in turbo pascal?

void CClock::doSetRemoteKeyCode(IRrecv &irrecv, decode_results &results)
{
bool bDone = false;
long unsigned *nStoredCode = &m_nUpArrowCode, nLastCode = 0;

while (!bDone)
{
memset(&results, 0, sizeof results);
irrecv.resume();

if (nStoredCode == &m_nUpArrowCode)
m_strPrompt = "HIT UP";
else if (nStoredCode == &m_nDownArrowCode)
m_strPrompt = "HIT DOWN";
else if (nStoredCode == &m_nLeftArrowCode)
m_strPrompt = "HIT LEFT";
else if (nStoredCode == &m_nRightArrowCode)
m_strPrompt = "HIT RIGHT";
else if (nStoredCode == &m_nEnterCode)
m_strPrompt = "Hit ENTER/OK";
else if (nStoredCode == &m_nExitCode)
m_strPrompt = "Hit EXIT/BACK/RETURN";
else if (nStoredCode == &m_nHomeCode)
m_strPrompt = "Hit HOME";

Serial.println(m_strPrompt);

while (results.value == nLastCode)
{
if (irrecv.decode(&results))
nLastCode = results.value;
}
irrecv.resume();
(*nStoredCode) = results.value;

if (results.value == nLastCode)
{
Serial.println("PPPPPPPPPPPPPPPPP");
Serial.println("nLastCode = ");
Serial.println(nLastCode);
Serial.println("results.value = ");
Serial.println(results.value);
Serial.println("PPPPPPPPPPPPPPPPP");
}
else if (nStoredCode == (&m_nUpArrowCode))
nStoredCode = &m_nDownArrowCode;
else if (nStoredCode == &m_nDownArrowCode)
nStoredCode = &m_nLeftArrowCode;
else if (nStoredCode == &m_nLeftArrowCode)
nStoredCode = &m_nRightArrowCode;
else if (nStoredCode == &m_nRightArrowCode)
nStoredCode = &m_nEnterCode;
else if (nStoredCode == &m_nEnterCode)
nStoredCode = &m_nExitCode;
else if (nStoredCode == &m_nExitCode)
nStoredCode = &m_nHomeCode;
else if (nStoredCode == &m_nHomeCode)
nStoredCode = NULL;

bDone = nStoredCode == NULL;
}
memset(&results, 0, sizeof results);
m_nMode = m_eDisplayTime;
}

Or is there some way to make IRRecive ignore pulses from the tv remote for a longer period of time before it returns a result to the caller of decode(...);

Last remote I used transmitted the code 3 times per button press, not sure if this was the duration at which I held the button down, or whether that's what it did per single button presses.
You could use a finite state machine to do what you want, I've posted a method using a FSM, but as you can see there's a lot of repeated code, I'll leave that to you to clean up if it all works how you want.

Something along these lines:

typedef enum
{
	UP = 0,
	DOWN,
	LEFT,
	RIGHT,

	COUNT,
	START,
	FINISHED,
}states_s;
int g_codes[COUNT] = { -1, -1, -1, -1 };
int g_state = UP;

void loop()
{
	switch( g_state )
	{
		case START:
			Serial.print( "Press UP" );
		case UP:
		{
			if (irrecv.decode(&results)) 
			{
				if( verify_code( results.value ))
				{
					Serial.print( "Press DOWN" );
					g_codes[g_state] = results.value;
					g_state = DOWN;
				}
			}
		}
		break;
		case DOWN:
		{
			if (irrecv.decode(&results)) 
			{
				if( verify_code( results.value ))
				{
					Serial.print( "Press LEFT" );
					g_codes[g_state] = results.value;
					g_state = LEFT;
				}
			}
		}
		break;
		case LEFT:
		{
			if (irrecv.decode(&results)) 
			{
				if( verify_code( results.value ))
				{
					Serial.print( "Press RIGHT" );
					g_codes[g_state] = results.value;
					g_state = RIGHT;
				}
			}
		}
		break;
		case RIGHT:
		{
			if (irrecv.decode(&results)) 
			{
				if( verify_code( results.value ))
				{
					g_codes[g_state] = results.value;
					g_state = FINISHED;
				}
			}
		}
		break;
	}
}

bool verify_code( int code )
{
	for( int i=0; i<COUNT; i++ )
	{
		if( code == g_codes[i] )
			return false;
	}
	return true;
}

once you get a valid code, put in a delay(1000); before issuing the irrecv.resume();

Just to confuse things further, one of the remotes I was using gives a totally different code if you hold a button down rather than just press it once. Some of my problems were related to this because I assumed that the codes for a button would be the same regardless of the duration of the press.

Some protocols have wht is called aa toggle bit (RC5 & RC6 etc)

On one press the toggle bit is ON (binary 1) and on the next OFF (binary 0) - to distinguish between button presses.
If you keep the button pressed, you get the same value for toggle bit when the signal is repeated.

You have described something different, but I supect it may actually be the toggle bit.