[Coco] Inkey loops

L. Curtis Boyle curtisboyle at sasktel.net
Thu Aug 1 12:21:11 EDT 2019


Depending on how your routine is to work, if you are literally waiting for a key press to exit a loop, then the best is probably to do an F$Sleep system call in between inkey reads.

A bit of example code might be:

TYPE registers=cc,a,b,dp:BYTE;x,y,u:INTEGER
DIM regs:registers
DIM key:STRING[1]
LOOP
  RUN inkey(key)
(* Exit LOOP/ENDLOOP if a key is pressed
EXITIF key<>”” THEN
ENDEXIT
(* F$Sleep call - remainder of our time slice
  regs.x=1
  RUN syscall($A,regs)
ENDLOOP

F$Sleep with X=1 means to give up the remainder of the time slice for our process to the rest of the system (about 1/10th of a second).

L. Curtis Boyle
curtisboyle at sasktel.net



> On Aug 1, 2019, at 9:03 AM, coco at jechar.ca wrote:
> 
> All
> 
> In a basic09 program can you suggest the best way to make an inkey loop without too much
> cpu overhead ie perhaps using a timer function ?
> 
> My previous basic09 programs only used command line parameters rather then interactive input
> after the program was started.
> 
> Charlie
> 
> -- 
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco
> 



More information about the Coco mailing list