class InputTask : public ITask
{
public:
...
bool CurrentKey(usint _index)
{
return (actKeys[_index] != 0 );
}
// -------------------------------------------------
bool OldKey(usint _index)
{
return (oldKeys[_index] != 0 );
}
// -------------------------------------------------
bool KeyboardKeyNowDown(usint _index)
{
return ( (CurrentKey(_index))) && (!OldKey(_index));
}
// -------------------------------------------------
bool KeyboardKeyStillDown(usint _index)
{
return ( CurrentKey(_index)) && ( OldKey(_index));
}
// -------------------------------------------------
uchar * actKeys;
uchar * oldKeys;
ulint keyCount;
};
bool InputTask :: Start()
{
actKeys = SDL_GetKeyState((int*) &keyCount );
oldKeys = new uchar[keyCount];
if (!oldKeys) return false;
SDL_PumpEvents();
SDL_PumpEvents();
return true;
}
void InputTask :: Update()
{
SDL_PumpEvents();
...
memcpy( oldKeys, actKeys, sizeof(uchar) * keyCount);
actKeys = SDL_GetKeyState((int*) &keyCount);
}
void InputTask :: Stop()
{
delete [] oldKeys;
}
Keyboard input system in SDL
Hi Well, I've got problem inside my InputSystem (based on Enginuity's). Before I explain what's wrong, please look at the code (cut unrelated things): Now, at first glance everything looks nice, but when you run test program, you'll notice that KeyboardKeyNowDown doesn't work! I've experimented with it for some time but nothing helped. I's even more strange beacose KeyboardKeyStillDown works fine, and it's design is very similiar to KeyboardKeyNowDown. Additionaly, I use identical approach when dealing with mouse input, and do I have to tell that it works perfectly? :-] I've taken this code (and slightly modificated it) from Enginuity's sources, hopeing that it would work. Well, in one little detail it isn't ;-) so now I hope there is at least one person who implemented similiar code and can give me some advices what's wrong with it :-) Thanks in advance! P.S. Yes, I've posted similiar post in Article Feedback but no one replied :-/ and this topic is very important to me.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement