Search code examples
pythonkeyncurses

Python curses - can't get TAB key


I need to catch TAB key in Python. For any other keys I do:

x = self.myscreen.getch()
if( x == curses.KEY_DOWN ):
  # and so..

What's the constant for TAB key? I searched here (bottom of page) and tried every TAB contant.

I tried '\t' too. Is it possible? Thank you


Solution

  • Try:

    if ( x == ord('\t')):
        ...
    

    or

    if ( x == 9):
        ...
    

    You need to be sure to convert the character to an integer with ord() before comparing to the value from getch