Page 1 of 1

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

Posted: Thu May 01, 2008 6:32 pm
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)


Posted: Thu May 01, 2008 7:14 pm
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?

Posted: Thu May 01, 2008 8:39 pm
by xytroxon
This is on a Windows 98 machine from a MSDOS window.

Posted: Fri May 02, 2008 10:41 am
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'.

Posted: Fri May 02, 2008 5:14 pm
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