Try this (had worked for me)

if(inkey_active==1)
{
inkey_active=0;
wait(1);
}
...

Regards
TSGames