views:

71

answers:

1

Hello. I am writing python chatbot that displays output through console. Every half second it asks server for updates, and responds to message. In the console I can see chat log.

This is sufficient in most cases, however, sometimes I want to interrupt normal workflow and write custom chat answer myself. I would love to be able to press a button (or combination) that would switch to "custom reply mode". What is the best way to do that, or achieve similar result?

Thanks a lot!

+1  A: 

Using select.select() on sys.stdin will allow you to check if a key has been pressed at the terminal.

Ignacio Vazquez-Abrams
Could you give example of select.select() parameters? I am googling and I only find bugs related to windows (I am using UNIX console).which kind of parameter should I need - rlist, wlist or xlist?thanks!
flixic
You read from `sys.stdin`.
Ignacio Vazquez-Abrams
Great! This works quite well: def heardEnter(): i,o,e = select.select([sys.stdin],[],[],1) for s in i: if s == sys.stdin: input = sys.stdin.readline() return True return False
flixic