Hi Charles
Interesting. It works fine. I think there is differences between your program and GETKEY :
- if you call 2 times TRY1 and a key is pushed (and not released) , it will returs 2 times the code key. I imagine GETKEY would only returns the key for the first call (if you don't release the key and push again)as it uses the keyboard buffer.
- The buffer is not cleared with ISKEYDOWN (you can can clear it with a call of GETKEY if ISKEYDOWN)
To manage the keyboard, we need 3 functions :
1/ GETKEY (to read the last key in the buffer)
2/ ISKEYDOWN (to scan the keyboard in real time)- Perfect for games ;)
3/ WAIT(0) like the 50G : stop the program, and wait until a key is down and then return the key number - low power consumption)
PS : I've not tried yet, but it will be interesting to see if ISKEYDOWN can manage multiple keys down in the same time
EDIT : Yes you can, with the real calc (not with 17565 rev emulator (perhaps because of the PC keyboard ? You can't push 2 keys only with the mouse ;) ) :
EXPORT MyFirstGame
BEGIN
LOCAL k;
REPEAT
k:="";
IF ISKEYDOWN(10) THEN k:=k+" Right"; END;
IF ISKEYDOWN(14) THEN k:=k+" Left"; END;
IF ISKEYDOWN(9) THEN k:=k+" Up"; END;
IF ISKEYDOWN(15) THEN k:=k+" Down"; END;
IF ISKEYDOWN(6) THEN k:=k+" FIRE"; END;
GETKEY;RECT(); TEXTOUT_P(k,10,10);WAIT(0.05);
UNTIL 0;
END;
So you can handle FIRE and Left/Right keys pressed in the same time
Another example :
EXPORT MyFirstGame
BEGIN
LOCAL k,m,t,n;
k:={
{32," seven "},{33," eight "},{34," nine "},
{37," four "} ,{38," five "} ,{39," six "},
{42," one "} ,{43," two "} ,{44," three "},
}
REPEAT
t:="";
FOR n FROM 1 TO 9 DO
m:=k(n);
IF ISKEYDOWN(m(1)) THEN t:=t+m(2); END;
END;
RECT(); TEXTOUT_P(t,10,10);
WAIT(0.05);
UNTIL 0;
END;
Is it possible to access to one item of a sublist to avoid use of temporary variable (m in this exemple) ?
For example here :(i want to get "nine")
k(3,2) -> Number of argument error
k(3)(2) -> k(3)*(2)
The only way i have found is : m:=k(3); ....m(2)...
Edited: 12 Aug 2012, 9:41 a.m.