Strange input behaviour

Hello everyone, it’s my first post here (but I’ve been watching this list for some time)

I’ve borrowed kernel/task design from Enginuity (series of articles on GameDev) and slightly modificated it to fit into my needs, I also borrowed it’s input design. Now my input system looks like this (cut unrelated things):

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; // unsigned char
uchar * oldKeys;
ulint keyCount; // unsigned long int

};

bool InputTask :: Start()
{
actKeys = SDL_GetKeyState((int*) &keyCount );
oldKeys = new uchar[keyCount];

if (!oldKeys) return false;

// call twice to flush any pending key presses
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;
}

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 be precise, it’s nearly identical except for !) to KeyboardKeyNowDown. Additionaly, I use identical approach when dealing with mouse input, and do I have to tell that it works perfectly? :-] I’ve run out of ideas what can be wrong here, so any advices will be very appreciated!

Thanks in advance!–
Koshmaar
<Of all the things I’'ve lost, I miss my mind the most>
GG: 3928072
http://jnr.sourceforge.net/
www.pongowar.prv.pl
www.liero-turbo.prv.pl

Onet wrote:

ulint keyCount; // unsigned long int
actKeys = SDL_GetKeyState((int*) &keyCount );

if SDL_GetKeyState want’s an int*, then give it a real int* not a cast.
if you print out keyCount after that call, what do you get?

-LIM-

Thanks for such quick response!

if SDL_GetKeyState want’s an int*, then give it a real int* not a cast.

Ok, I’ve changed keyCount to normal int, now it’s without a cast.

if you print out keyCount after that call, what do you get?

Well, it’s very strange - I get “keyCount == 323” (yes, I’ve got normal 108 keys-or-so keyboard ;-)) ?!? Of course SDL_GetKeyState is called after SDL_Init() etc.

Koshmaar

Well, it’s very strange - I get “keyCount == 323” (yes, I’ve got normal 108 keys-or-so keyboard ;-)) ?!? Of course SDL_GetKeyState is called
after SDL_Init() etc.

Ups! Sorry for dumb answer, now I’ve reminded that there are 323 SDLK_* defines! But in this case that bug is getting even more mysterious and weird… :-/
BTW: sorry for double post.

Koshmaar