Re: Processing a key pressed in Python 3.6

2018-01-24 Thread eryk sun
On Wed, Jan 24, 2018 at 8:02 PM, Virgil Stokes wrote: > Yes, I am aware of this Dennis. However, but, on my system I actually had it > running without the msvcrt.kbhit() _getwch loops calling ReadConsoleInput until a key event is read. The key can be typed manually in the console, or posted (i.e.

Re: Processing a key pressed in Python 3.6

2018-01-24 Thread Virgil Stokes
Yes, I am aware of this Dennis. However, but, on my system I actually had it running without the msvcrt.kbhit() This occurred during testing while trying different options. And I was able to reproduce this several times. Why? I do not have an answer. This is one reason why I posted the code. I

Re: Processing a key pressed in Python 3.6

2018-01-23 Thread Virgil Stokes
Ok Dennis, You were correct. The following also works in the Windows 10 command window. import time import msvcrt while "more work to do":     print("Getting data...")     time.sleep(1)     print("Saving data to file...")     time.sleep(1)     key = msvcrt.getwch()     #print('key: %s'%key)  #

Re: Processing a key pressed in Python 3.6

2018-01-23 Thread MRAB
On 2018-01-23 23:29, Virgil Stokes wrote: Another follow-up question: How would this code be modified to handle using the "Esc" key instead of the "Enter" key? This version uses msvcrt on Windows: import msvcrt import threading import time shutdown = False def wait_for_enter(): global s

Re: Processing a key pressed in Python 3.6

2018-01-23 Thread eryk sun
On Tue, Jan 23, 2018 at 11:29 PM, Virgil Stokes wrote: > > How would this code be modified to handle using the "Esc" key instead of the > "Enter" key? The input() function depends on the console or terminal to read a line of input. If you're using the Windows console, it calls the high-level Read

Re: Processing a key pressed in Python 3.6

2018-01-23 Thread Virgil Stokes
Another follow-up question: How would this code be modified to handle using the "Esc" key instead of the "Enter" key? On 2018-01-23 20:15, Chris Angelico wrote: On Wed, Jan 24, 2018 at 5:50 AM, Virgil Stokes wrote: I would appreciate help on finding a solution to following problem. This is

Re: Processing a key pressed in Python 3.6 🦉

2018-01-23 Thread Virgil Stokes
Thanks very much Chris, This code worked perfectly for "Enter". Your knowledge of  Python and more specifically this elegant solution are greatly appreciated. I now know that I need to learn more about threads. :-) On 2018-01-23 20:15, Chris Angelico wrote: On Wed, Jan 24, 2018 at 5:50 AM, V

Re: Processing a key pressed in Python 3.6

2018-01-23 Thread Chris Angelico
On Wed, Jan 24, 2018 at 5:50 AM, Virgil Stokes wrote: > I would appreciate help on finding a solution to following problem. This is > the general structure of the "problem" code: > >> while True >> # Get some data from the web and process it >> ... >> ... >> # Write these data to a

Processing a key pressed in Python 3.6

2018-01-23 Thread Virgil Stokes
I would appreciate help on finding a solution to following problem. This is the general structure of the "problem" code: while True     # Get some data from the web and process it     ...     ...     # Write these data to a file     ...     ...     # Check if a_key has been pressed in the comma