title: Use getch in while (1) python
body: <p>I would like to use <code>char=getch.getch()</code> in a loop (<code>while(1)</code>). 
  The problem when I use this like that it block my loop:</p>
  
  <pre><code>import getch
  
  while(1):
           char=getch.getch()
           a=read_data()
           if (char=='a'): c=....
           if (char=='b'): c=.... 
  </code></pre>
  
  <p>If I don't put anything, my loop is blocked... How can I solve this for getting event from my keyboard?</p>
  
  <p><strong>EDIT</strong> : At the top is an example of what I want to do but if you are interested, my real script is here. I am actually working on an analyser spectrum and I want to scan by pressing some keys:</p>
  
  <pre><code>from pylab import *
  from rtlsdr import *
  from bluetooth import *
  
  import sys
  import matplotlib.pyplot as plt
  import matplotlib.animation as animation
  import getch
  
  sdr=RtlSdr()
  
  #configure device
  sdr.center_freq=double(sys.argv[1]) # centrale frequency
  sdr.gain=double(sys.argv[2]) #gain
  sdr.sample_rate=double(sys.argv[3]) # sample rate
  
  #configure PSD
  NFFT=int(sys.argv[4]) # nb points
  
  # Bluetooth connexion
  server_sock=BluetoothSocket( RFCOMM )
  server_sock.bind(("",PORT_ANY))
  server_sock.listen(1)
  port = server_sock.getsockname()[1]
  uuid="94f39d29-7d6d-437d-973b-fba39e49d4ee"
  client_sock, client_info=server_sock.accept()
  
  while (1):
  
      samples=sdr.read_samples(256*1024)
          result=psd(samples,NFFT,Fs=sdr.sample_rate/1e6,Fc=sdr.center_freq*1e6/1e6)
  
          tab_freq=(result[1]/1e6)
          value_freq=str(tab_freq)[1:-1]
          value_list=[format(float(v), ".5f") for v in value_freq.split()]
          value_freq2= "\n".join(value_list)
  
          tab_pxx=result[0]
          value_pxx=str(tab_pxx)[1:-1]
          value_list2=[format(float(v), ".7f") for v in value_pxx.split()]
          value_pxx2= "\n".join(value_list2)
  
          client_sock.send(value_freq2+'\n'+'\n'.join(value_pxx2.split()))
  
          char=getch.getch()
  
          if (char=='a'):
          sdr.center_freq=sdr.center_freq+0.1e6
          print 'center_freq+'
          if (char=='z'):
          sdr.center_freq=sdr.center_freq-0.1e6
          print 'center_freq-'
  </code></pre>