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

Started by xytroxon, May 01, 2008, 11:32:02 AM

Previous topic - Next topic

xytroxon


;(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

#1
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)


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

#2
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

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

xytroxon

#4
Quote from: "Lutz"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/">//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