Keyboard Codes

What are the bytes I get reading stdin when I press a Key of the keyboard
after setting the terminal to raw? On what they depend? On the operating
system?

You can see them with my tcl script bellow. For example:

Ascii -> Asci byte
ä,ö,ü -> their utf-8 (c3-a4, c3-b6, c3-bc)
up, down, right, left arrow -> 1b-5b-41, 1b-5b-42, 1b-5b-43, 1b-5b-44 ????
F1, Shift F1, Alt F1 -> 1b-4f-50, 1b-5b-31-3b-32-50, 1b-5b-31-3b-33-50 ???
F5, Shift F5, Alt F5, Shift Alt F5 -> 1b-5b-31-35-7e, 1b-5b-31-35-3b-32-7e, 1b-5b-31-35-3b-33-7e, 1b-5b-31-35-3b-34-7e ???
And so on


Code:
#!/usr/opt/bin/tclsh

fconfigure stdin -encoding binary

proc readk {} {
set ttyst [exec stty -g]
exec /bin/stty raw -echo <@stdin
append key [binary encode hex [read stdin 1]]
set n [chan pending input stdin]
while {$n} {append key -[binary encode hex [read stdin 1]]; incr n -1}
exec /bin/stty -raw echo <@stdin
exec /bin/stty $ttyst <@stdin
return $key}

# leave with ^D
while {[set k [readk]] ne 04} {puts $k}
 
Back
Top