Tecnical question to devs.


Gabriele Battaglia
 

Hello.

I apologize to those who aren't interested. Here is a tecnical question specific to developers or to those of you who have programming skills.


As you may know, I like programming some small tools with Python3.

My script run on console only, at least for the moment, :)


I'm always searching for a non-blocking input method which allows me to monitor the keyboard while the script is doing something else.


Before I wanted to create cross-platform applications, so I couldn't use solution from Microsoft. But now that I'm more and more disappointed from VoiceOver on MacOS, I'm dismissing my iMac computer and rebuilt my home station back on Windows again. So I can use MS solution even though I won't be able to give my script to those blind friend who continue to use MacOS on their computers.


What I need is called msvcrt, with its functions kbhit (a boolean value true when a key is pressed and getwch which reports that key). There would be also getch but I don't still know exactly what it is for.


The problem with NVDA is for instance,

if I wrote this:


import msvcrt

print("Gimme a character: ",end="")
while True:
    if msvcrt.kbhit:
        choice=msvcrt.getwch()
        break
print(choice)

NVDA speaks out the output but I have nothing on my Braille display.

On the other hand, if I import sys also and I call sys.stdout.flush() after the print() statement, I can read the output normally as it happens with a simple print() statement.


Now, 4 questions:

1. Why this happens on my Braille Display?
2. What is flush and what it does?

3. Is there some, more elegant :) way to fix this problem?

4. Do you know some library, simple to use, for a non-blocking input pourpose?


Many, many thanks to all.

Gabe.

Join nvda@nvda.groups.io to automatically receive all group messages.