10 a$=inkey$
20 if stick(0)=1 then gosub 50: goto 40
30 goto 10
40 defusr=&h156: a=usr(0): print "done": end
50 if stick(0)=1 then 50 else return
as long as the key remains pressed, the program remains in line 50.
after release it goes to line 40 where the keyboard buffer gets emptied and the program ends.
I've been looking around in some old examples from magazines and came up with this:
10 A$=INKEY$: IF A$<>"" THEN GOSUB 30 ELSE 10
20 PRINT A$;" pressed": DEFUSR=&H156: A=USR(0): END
30 B=0: FOR I=0 TO 10: A(I)=PEEK(I+&HFBDA): B=B+A(I): NEXT I: IF B<2805 THEN 30 ELSE RETURN
It scans the keyboard on pressed keys... If a key is pressed B will be < 2805
While brainstorming a bit with Bifi the code got optimized to compare newkey / oldkey
10 A$=INKEY$: IF A$<>"" THEN GOSUB 30 ELSE 10
20 PRINT A$;" pressed": DEFUSR=&H156: A=USR(0): END
30 B=255: FOR I=0 TO 10: B=B AND PEEK (&HFBE5+I): NEXT: IF B<>255 THEN 30 ELSE RETURN
This one is a tad faster and consumes quite a lot less memory than mine. Bifi stated that using arrays in this case is a pity for the memory it consumes. My versions takes 131 bytes and Bifi's version takes 35 bytes... If you can live with that, this could be a way...