Key Press Not Working

MRAB python at mrabarnett.plus.com
Thu Nov 2 23:11:37 EDT 2017


On 2017-11-03 02:40, brandon wallace wrote:
> 
>   
> I am trying to catch a key press but it is not working. How can I fix this code? There is no error message so there is no error message to do a search on.
> I am using Python3.5 64-bit inside the terminal.
> 
> while True:
>      key = input("Enter a letter: ")
>      if key == ord('q'):
>           break
>   
>   The loop keeps running even though I have pressed the letter 'q'.
> 
It's waiting for you to press Enter.

'input' is for inputting a line. It returns a string.

 >>> s = input("Enter a line: ")
Enter a line: foo
 >>> s
'foo'



More information about the Python-list mailing list