Don't know if this will help (offered as "food for thought") but this is a function in my library that stays in a loop until the user presses a key and then returns the character corresponding to the key pressed, including the escape key (ASCII code 27 = "\e"), kinda like C's getchar function.
(defun _GetChar ( / data key result done )
[color=green];; return the character for the key pressed[/color]
(while (not done)
[color=green];; stay in the loop until the user presses a key[/color]
(vl-catch-all-apply
'(lambda ( )
(setq
data nil
data (grread nil 14 1)
)
)
)
(setq
key (car data)
result (cadr data)
)
(cond
[color=green];; user pressed <esc>[/color]
((null data) (setq done t result 27))
[color=green];; user pressed a key[/color]
((eq 2 key) (setq done t))
[color=green];; user hit right mouse button, consider same as enter[/color]
((eq 25 key)(setq done t result 13))
)
)
(chr result)
)