;; keyboard setup -- that's simple!
(set-input-mode nil nil 0)
(define-key function-key-map [backspace] "\177") ; Normal behaviour for BS
(define-key function-key-map [delete] "\C-d")    ; ... and Delete
(define-key function-key-map [tab] [?\t])
(define-key function-key-map [linefeed] [?\n])
(define-key function-key-map [clear] [11])
(define-key function-key-map [return] [13])
(define-key function-key-map [escape] [?\e])
(define-key function-key-map [M-backspace] [?\M-\d])
(define-key function-key-map [M-delete] [?\M-\d])
(define-key function-key-map [M-tab] [?\M-\t])
(define-key function-key-map [M-linefeed] [?\M-\n])
(define-key function-key-map [M-clear] [?\M-\013])
(define-key function-key-map [M-return] [?\M-\015])
(define-key function-key-map [M-escape] [?\M-\e])

(define-key function-key-map [kp-f1] "?\e[11~")
(define-key function-key-map [kp-f2] "?\e[12~")
(define-key function-key-map [kp-f3] "?\e[13~")
(define-key function-key-map [kp-f4] "?\e[14~")
(define-key function-key-map [kp-f5] "?\e[15~")
(define-key function-key-map [kp-f6] "?\e[16~")
(define-key function-key-map [kp-f7] "?\e[17~")
(define-key function-key-map [kp-f8] "?\e[18~")
(define-key function-key-map [kp-f9] "?\e[19~")
(define-key function-key-map [kp-f10] "?\e[20~")
(define-key function-key-map [kp-f11] "?\e[21~")
(define-key function-key-map [kp-f12] "?\e[22~")

(put 'backspace 'ascii-character 127)
(put 'delete 'ascii-character 127)
(put 'tab 'ascii-character ?\t)
(put 'linefeed 'ascii-character ?\n)
(put 'clear 'ascii-character 12)
(put 'return 'ascii-character 13)
(put 'escape 'ascii-character ?\e)
