The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Having a issue with previous and current state of keys
smilesprower


Joined: 21 Oct 2016
Posts: 6
I am trying to implement a keyboard that will allow me to check a key press. "Previous state was up and Current State is down"
If I hammer the keyboard really fast the event will eventually pop, but its so random and not working as expected.


// Keyboard Update
void Keyboard::update()
{
memcpy(m_previousState, m_currentState, this->length);
SDL_PumpEvents();
m_currentState = SDL_GetKeyboardState(NULL);
}
// Key Pressed
bool Keyboard::keyPressed(int key)
{
if (m_currentState[key] && !m_previousState[key])
return true;
else
return false;
}
smilesprower


Joined: 21 Oct 2016
Posts: 6
Problem fixed.
I was also using Events which was causing a conflict.