(read-key) side effect on (read-line)

Notices and updates
Locked
xytroxon
Posts: 296
Joined: Tue Nov 06, 2007 3:59 pm
Contact:

(read-key) side effect on (read-line)

Post by xytroxon »

Code: Select all

;(Note: This entire code section can be copied to a file for testing.)
;
; Hi Lutz!
;
; I'm having a problem with the following console code
; using newLISP v.9.3.11 on Win32 IPv4
;
(print "Press <Enter> key to input name. ")
(setq key (read-key))
(println "Key pressed: " key)
(if (= key 13)
	(begin
		(print "Enter name: ")
		(setq line (read-line))
		(println line)
	)
)
;
; Program output:
; ---------------------------------------------------------
; Press <Enter> to input name. Key pressed: 13
; Enter name:
; ---------------------------------------------------------
;
; Program continues without allowing line to be input.
;
; So let's try a different key...
;
(print "Press </> key to input name. ")
(setq key (read-key))
(println "Key pressed: " key)
(if (= key 47)
	(begin
		(print "Enter name: ")
		(setq line (read-line))
		(println line)
	)
)
; 
; Program output:
; ---------------------------------------------------------
; Press </> to input name. Key pressed: 47
; Enter name: /
; ---------------------------------------------------------
; 
; This time it allows input, but prepends "/" to the input
; prompt. Typing in the name and pressing <Enter> is now
; allowed.
;
; ---------------------------------------------------------
; Enter name: /xytroxon <Enter>
; /xytroxon
; ---------------------------------------------------------
;
; Pressing <Backspace> will erase the extra "/". So the 
; problem is that the (read-key) function is not consuming
; the key press and is carried over into (read-line)...
;
; -- xytroxon
(exit)

"Many computers can print only capital letters, so we shall not use lowercase letters."
-- Let's Talk Lisp (c) 1976

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

Post by Lutz »

I have tried your program on Mac OS X, FreeBSD and Solaris using 10 for the enter key and on Windows XP SP 2 using enter with 13, and they all work correctly, producing the following (on Win32 with 13)

Code: Select all

Press <Enter> key to input name. Key pressed: 10
Enter name: hello world
hello world
What OS are you using?

ps: seeing the 13, I guess your are using Windows. Are you using the standard Windows command shell or something special?

xytroxon
Posts: 296
Joined: Tue Nov 06, 2007 3:59 pm
Contact:

Post by xytroxon »

This is on a Windows 98 machine from a MSDOS window.
"Many computers can print only capital letters, so we shall not use lowercase letters."
-- Let's Talk Lisp (c) 1976

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

Post by Lutz »

Perhaps you can find older Windows SDK documentation, lookup an appropriate function for character input and make it available to newLISP using 'import'.

xytroxon
Posts: 296
Joined: Tue Nov 06, 2007 3:59 pm
Contact:

Post by xytroxon »

Lutz wrote:Perhaps you can find older Windows SDK documentation, lookup an appropriate function for character input and make it available to newLISP using 'import'.
Yes, I can do that.

It's just strange, as newLISP works so smoothly otherwise!

newLISP breaths newLIFE into "This Old Notebook"! (Isn't that a newPBS show? :;

Using the newLISP wiki as a PIM with the very light weight Abyss web server has been greaat fun!

http://www.aprelium.com/

-- xytroxon
"Many computers can print only capital letters, so we shall not use lowercase letters."
-- Let's Talk Lisp (c) 1976

Locked