NCurses and ESC,ALT keys
Here is an example for python:
key = self.screen.getch()
if key == ord('q'): # quit
go = False
elif key == 27: # Esc or Alt
# Don't wait for another key
# If it was Alt then curses has already sent the other key
# otherwise -1 is sent (Escape)
self.screen.nodelay(True)
n = self.screen.getch()
if n == -1:
# Escape was pressed
go = False
# Return to delay
self.screen.nodelay(False)
Resolved by:
- Use noecho or timeout mode
- Check for 27(ALT or ESC) code... if pass:
- try to read another code
- if another code is ERR then.. you have ESC key in other way you have ALT+another code