-- find out what numeric key code/sequence is generated by any key on the
-- keyboard. xkey is useful for working in terminals (xterm, etc).
-- usage (on Linux):
--          exu xkey

include machine2.e

object code	-- code may be an integer or a string of integers

puts(1, "Press any key. I'll show you the key code. Press q to quit\n\n")
while 1 do
    code = get_xkey()
    if not equal(code, -1) then
	if (atom(code) and code < 32) or (sequence(code) and code[1] = 27) then
	    puts(1, "Key: " & ' ') -- skip control character or escape sequence
	else
	    puts(1, "Key: " & code) -- puts the character itself
	end if

	puts(1, "  Code: ")
	? code

	if equal(code, 'q') then
	    exit
	end if
    end if
end while
