Have a counter which updates every tenth of a second: if the counter is bigger than zero then counter = counter - 1. Now on keyhit <space> set counter to 20. Now you can check the counter to figure out if <space> was pressed within the last two seconds.