Hi every1.
Here’s my task:
I need to know exactly what key was pushed down/released up during the exact current frame. So that on the next frame keys that being held won’t generate duplicate events/messages.
Still, I want to get repeated key events.
My current solution is:
const Uint8* curKeys = SDL_GetKeyboardState( 0 );
const Uint8* newKeys = curKeys;
Uint8 downKeys[ 512 ];
Uint8 upKeys[ 512 ];
// main loop start
while( running ) {
// ...
// TODO: update input
SDL_PumpEvents();
newKeys = SDL_GetKeyboardState( 0 );
for ( int i = 0; i < 512; i++ ) {
downKeys[ i ] = 0;
upKeys[ i ] = 0;
if ( !curKeys[ i ] && newKeys[ i ] )
downKeys[ i ] = 1;
if ( curKeys[ i ] && !newKeys[ i ] )
upKeys[ i ] = 1;
}
curKeys = newKeys;
if ( curKeys [ SDL_SCANCODE_F ] )
std::cerr << "'f' is pressed\n";
if ( downKeys [ SDL_SCANCODE_F ] )
std::cerr << "'f' is down\n";
if ( upKeys [ SDL_SCANCODE_F ] )
std::cerr << "'f' is up\n";
//...
}
The problem is that downKeys and upKeys are not functional - I’m getting response only from curKeys.
What am I doing wrong ? Somebody?