--****
-- === key.ex
--
-- Find out what numeric key code is generated by any key on the keyboard
--
-- ==== Usage
-- {{{
-- eui key [keybindfile]
-- }}}
-- If you supply a valid file containing key bindings, they will be set prior to
-- testing the keycodes returned.

include std/os.e
include std/console.e
include std/io.e

sequence cmd
cmd = command_line()

if length(cmd) >= 3 then
  set_keycodes(cmd[3])
  writefln("Testing keyboard codes on [1] using bindings from [2]", {uname(), cmd[3]})
else
  writefln("Testing keyboard codes on [1]", {uname()})
end if


puts(1, "Press any key. I'll show you the key code. Press q to quit\n")
while 1 do
	integer code = get_key()
	if code != -1 then
		printf(1, "The key code is: %d\n", code)
		if code = 'q' then
			exit
		end if
	end if
end while
