Is keyPressed working if the key was pressed seconds before?
Posted: Mon Sep 19, 2011 11:06 am
Hi,
I'm trying to write just a simple script to detect if a key was pressed.
The script needs i.e 5 seconds for a while loop. If I press and hold the key, it is detected, but not if the key is currently not pressed while calling keyPressed.
i.e.
if the script sleeps (yrest) and the button is pressed, nothing is being traced.
If holding the key the next loop and call of (keyPressed) is detected.
Can you please tell me what is wrong?
Thanks
Siegmund
I'm trying to write just a simple script to detect if a key was pressed.
The script needs i.e 5 seconds for a while loop. If I press and hold the key, it is detected, but not if the key is currently not pressed while calling keyPressed.
i.e.
Code: Select all
...
setting_DoLooting = 1;
while(true) do
cprintf(cli.yellow, "x: %s\n\r", x);
x=x+1;
if( keyPressed(key.VK_NUMPAD4) ) then
if (setting_DoLooting == 1) then
TRACE(50, cli.red, "stop lootingn\r");
setting_DoLooting = 0
else
TRACE(50, cli.green, "LOOT = ON\n\r");
setting_DoLooting = 1
end
end
yrest(1000);
end
If holding the key the next loop and call of (keyPressed) is detected.
Can you please tell me what is wrong?
Thanks
Siegmund