key-pressed or (read function with a time out

Started by CaveGuy, August 08, 2017, 07:56:56 AM

Previous topic - Next topic

CaveGuy

WANTED: The able to test for a key-pressed or be able to time out from a (read- like function.



The object is to be able to interrupt a loop with a key stroke. currently all input functions are blocking and wait forever for input. Sometimes when no input is forth coming we need to be able to move on.  



(net-peek and (net-connect with it's timeout are good examples of non-blocking input.



In windows we have the following workaround but nothing I can figure out for the other os's



(if (not _kbhit) (import "msvcrt.DLL" "_kbhit" ))
(if (not _getch) (import "msvcrt.DLL" "_getch" ))

(define (key-pressed)
  (if (= 0 (_kbhit)) nil
      (begin
         (setq keyval (_getch))
         (if (or (= keyval 0)(= keyval 224)) (CONSOLE:_getch))
         (setq keypress (char keyval)))))
Bob the Caveguy aka Lord High Fixer.

Lutz

#1
In version 10.7.3 a 'true' flag parameter in 'read-key' enables non-blocking behavior.



When using '(read-key true)' a 0 (zero) is returned when no key was pressed or the key code is returned when a key was pressed.



http://newlisp.nfshost.com/downloads/development/inprogress/">http://newlisp.nfshost.com/downloads/de ... nprogress/">http://newlisp.nfshost.com/downloads/development/inprogress/



Tested on macOS, Ubuntu  Linux, FreeBSD, OpenBSD and MS Windows.

CaveGuy

#2
Thank you! my only question is if 10.7.3 will be released as binaries for windows in the near future ?

Now I am retired the cost of maintaining the mickeysoft development tools has become prohibitive.

Bottom line is I no longer have a windows build environment on my current system and plan on using newlisp exclusively going forward.
Bob the Caveguy aka Lord High Fixer.

Lutz

#3
You can find an executable Windows version here:



http://newlisp.nfshost.com/downloads/development/inprogress/">http://newlisp.nfshost.com/downloads/de ... nprogress/">http://newlisp.nfshost.com/downloads/development/inprogress/

CaveGuy

#4
thanks, but I need a 32bit one. I will go into more detail why in a different thread.
Bob the Caveguy aka Lord High Fixer.

Lutz

#5
Both, 32-bit and 64-bit now here: http://www.newlisp.org/downloads/development/inprogress/">http://www.newlisp.org/downloads/develo ... nprogress/">http://www.newlisp.org/downloads/development/inprogress/