Index: main/input.lisp
===================================================================
--- main/input.lisp	(revision main,14)
+++ main/input.lisp	(revision main,14)
@@ -0,0 +1,168 @@
+;;;; TODO: Change all the keycode symbols to an enumeration so that
+;;;; Lisp will deetect typos, &c.
+
+(defpackage #:input
+  (:use #:cl #:cffi)
+  (:export))
+
+(in-package #:input)
+
+
+
+;;; These constants came from a human parsing the header.  Perhaps
+;;; they should be symbolized in a wrapper.
+
+(defconstant +ok+ 0)
+(defconstant +err+ -1)
+(defconstant +key-code-yes+ #o0400)
+
+
+
+(defctype wchar :int32)                 ; Checked on AMD64.
+
+(defcfun "wget_wch" :int
+  (window :pointer)
+  (wch :pointer))
+
+#|(defcfun "unget_wch" :int
+  ...)|#
+
+
+
+(defconstant +key-table+
+  '(#o0401 :key-break
+    #o0530 :key-soft-reset
+    #o0531 :key-hard-reset
+    #o0402 :key-down
+    #o0403 :key-up
+    #o0404 :key-left
+    #o0405 :key-right
+    #o0406 :key-home
+    #o0407 :key-backspace
+    #o0410 :key-f0
+    #o0411 :key-f1
+    #o0412 :key-f2
+    #o0413 :key-f3
+    #o0414 :key-f4
+    #o0415 :key-f5
+    #o0416 :key-f6
+    #o0417 :key-f7
+    #o0420 :key-f8
+    #o0421 :key-f9
+    #o0422 :key-f10
+    #o0423 :key-f11
+    #o0424 :key-f12
+    #o0510 :key-dl
+    #o0511 :key-il
+    #o0512 :key-dc
+    #o0513 :key-ic
+    #o0514 :key-eic
+    #o0515 :key-clear
+    #o0516 :key-eos
+    #o0517 :key-eol
+    #o0520 :key-sf
+    #o0521 :key-sr
+    #o0522 :key-npage
+    #o0523 :key-ppage
+    #o0524 :key-stab
+    #o0525 :key-ctab
+    #o0526 :key-catab
+    #o0527 :key-enter
+    #o0532 :key-print
+    #o0533 :key-ll
+    #o0534 :key-a1
+    #o0535 :key-a3
+    #o0536 :key-b2
+    #o0537 :key-c1
+    #o0540 :key-c3
+    #o0541 :key-btab
+    #o0542 :key-beg
+    #o0543 :key-cancel
+    #o0544 :key-close
+    #o0545 :key-command
+    #o0546 :key-copy
+    #o0547 :key-create
+    #o0550 :key-end
+    #o0551 :key-exit
+    #o0552 :key-find
+    #o0553 :key-help
+    #o0554 :key-mark
+    #o0555 :key-message
+    #o0556 :key-move
+    #o0557 :key-next
+    #o0560 :key-open
+    #o0561 :key-options
+    #o0562 :key-previous
+    #o0563 :key-redo
+    #o0564 :key-reference
+    #o0565 :key-refresh
+    #o0566 :key-replace
+    #o0567 :key-restart
+    #o0570 :key-resume
+    #o0571 :key-save
+    #o0572 :key-sbeg
+    #o0573 :key-scancel
+    #o0574 :key-scommand
+    #o0575 :key-scopy
+    #o0576 :key-screate
+    #o0577 :key-sdc
+    #o0600 :key-sdl
+    #o0601 :key-select
+    #o0602 :key-send
+    #o0603 :key-seol
+    #o0604 :key-sexit
+    #o0605 :key-sfind
+    #o0606 :key-shelp
+    #o0607 :key-shome
+    #o0610 :key-sic
+    #o0611 :key-sleft
+    #o0612 :key-smessage
+    #o0613 :key-smove
+    #o0614 :key-snext
+    #o0615 :key-soptions
+    #o0616 :key-sprevious
+    #o0617 :key-sprint
+    #o0620 :key-sredo
+    #o0621 :key-sreplace
+    #o0622 :key-sright
+    #o0623 :key-srsume
+    #o0624 :key-ssave
+    #o0625 :key-ssuspend
+    #o0626 :key-sundo
+    #o0627 :key-suspend
+    #o0630 :key-undo
+    #o0631 :key-mouse
+    #o0632 :key-resize
+    #o0633 :key-event))
+
+(defun %wget-wch (raw-window)
+  (with-foreign-object (ch 'wchar)
+    (let ((r (wget-wch raw-window ch)))
+      (cond
+        ((= r +ok+)
+         (code-char (mem-ref ch 'wchar)))
+        ((= r +key-code-yes+)
+         (getf +key-table+ (mem-ref ch 'wchar) :key-unknown))
+        ((= r +err+)
+         nil)
+        (t (error "Should not be here."))))))
+
+
+
+(defun test ()
+  (let ((screen (cdk::c-init-curses-screen)))
+    (cdk::c-cbreak)
+    (cdk::c-noecho)
+    (cdk::c-nonl)
+    (cdk::c-keypad screen t)
+    (loop
+       (let ((c (%wget-wch screen)))
+         (when (and (characterp c) (char= c #\Esc))
+           (return))
+         (format t
+                 (typecase c
+                   (character "~A")
+                   (keyword "~&~A~%")
+                   (t "~&UNKNOWN: ~A~%"))
+                 c))))
+  (cdk::c-end-curses))
