python need faster response with getch
<p>I'm trying to create a setup to blink a led and be able to control the frequency.
Right now I'm just printing 10s as placeholders for testing.
Everything runs and does what should, but getch is throwing me off.</p>

<pre><code>freq = 1
while freq &gt; 0:
    time.sleep(.5/freq) #half dutycycle / Hz
    print("1")
    time.sleep(.5/freq) #half dutycycle / Hz
    print("0")

    def kbfunc():
        return ord(msvcrt.getch()) if msvcrt.kbhit() else 0
    #print(kbfunc())

    if kbfunc() == 27: #ESC
        break
    if kbfunc() == 49: #one
        freq = freq + 10
    if kbfunc() == 48: #zero
        freq = freq - 10
</code></pre>

<p>Now when it starts up, the freq change portion seems buggy like it's not reading all the time or I have to time the press just right. The break line has no problem whenever pressed though.</p>

<p>There should be only one <code>kbfunc()</code> call. Store the result in a variable.</p>

<p>E.g.: In your code if the key isn't <code>Esc</code>, you'll read the keyboard again.</p>

python msvcrt getch