Run this: puts "Type any characters, then ." expect { ? { set result $expect_out(0,string) if {[string compare \n $result]} { scan $result %c value if {$value==27} { puts "You just typed Esc (decimal ASCII 27)." } { puts "You just typed '$result' (decimal ASCII $value)." } } exp_continue } } Example output: type "a", see decimal 97; type "", see the sequence 27-91-49-(49,50)-126 [[explain]] Win 95 ---- Also see "[keysyms]", CWIND [[?]], and "[How to send escape characters through Expect]". ---- [Csan] The original code did not handle the Esc $result properly - it ate the second ' character in the output. I added a branch to handle that case.