Page 1 of 1

key-pressed or (read function with a time out

PostPosted: Tue Aug 08, 2017 2:56 pm
by 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

Code: Select all
(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)))))

Re: key-pressed or (read function with a time out

PostPosted: Thu Aug 10, 2017 3:36 pm
by Lutz
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/de ... nprogress/

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

Re: key-pressed or (read function with a time out

PostPosted: Fri Aug 11, 2017 3:08 am
by CaveGuy
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.

Re: key-pressed or (read function with a time out

PostPosted: Fri Aug 11, 2017 1:33 pm
by Lutz
You can find an executable Windows version here:

http://newlisp.nfshost.com/downloads/de ... nprogress/

Re: key-pressed or (read function with a time out

PostPosted: Fri Aug 11, 2017 2:44 pm
by CaveGuy
thanks, but I need a 32bit one. I will go into more detail why in a different thread.

Re: key-pressed or (read function with a time out

PostPosted: Fri Aug 11, 2017 2:55 pm
by Lutz