key-pressed or (read function with a time out

For the Compleat Fan

key-pressed or (read function with a time out

Postby CaveGuy » Tue Aug 08, 2017 2:56 pm

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)))))
Bob the Caveguy aka Lord High Fixer.
CaveGuy
 
Posts: 110
Joined: Sun Oct 13, 2002 3:00 pm
Location: Columbus Ohio

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

Postby Lutz » Thu Aug 10, 2017 3:36 pm

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.
Lutz
 
Posts: 5231
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

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

Postby CaveGuy » Fri Aug 11, 2017 3:08 am

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.
CaveGuy
 
Posts: 110
Joined: Sun Oct 13, 2002 3:00 pm
Location: Columbus Ohio

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

Postby Lutz » Fri Aug 11, 2017 1:33 pm

You can find an executable Windows version here:

http://newlisp.nfshost.com/downloads/de ... nprogress/
Lutz
 
Posts: 5231
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California

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

Postby CaveGuy » Fri Aug 11, 2017 2:44 pm

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.
CaveGuy
 
Posts: 110
Joined: Sun Oct 13, 2002 3:00 pm
Location: Columbus Ohio

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

Postby Lutz » Fri Aug 11, 2017 2:55 pm

Lutz
 
Posts: 5231
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California


Return to Anything else we might add?

Who is online

Users browsing this forum: No registered users and 0 guests

cron