title: python - capture mouse input from user
body: <p>Recently, I started working on a small user interact program, which collects user mouse click and does some action. I wonder how I can treat mouse as a device, alongside QT, and capture its left, right and middle click, and wrap up into this class.</p>
  
  <pre><code>class UserInputProcessor:
  @abc.abstractmethod
  def process_user_input(self):
      pass
  </code></pre>
  
  <p>Here is what I did for a speech recognition for macrophone:</p>
  
  <pre><code>class SpeechProcessor(UserInputProcessor):
  def __init__(self, json_file_path = "speech_processor.json", credentials = ".credentials.json"):
  
          """set up microphone """
          self.process = True
  
  def process_user_input(self):
      with self.__microphone as source:
          while self.process:
              # Continuously wait for user input
              self.__speech_converter_params["audio_data"] = None
              while self.__speech_converter_params["audio_data"] == None:
                  try:
                      self.__speech_converter_params["audio_data"] = self.__recognizer.listen(
                          source,
                          phrase_time_limit = self.__config["phrase_time_limit"],
                          timeout = self.__config["timeout"])
                  except sr.WaitTimeoutError:
                      print("Timing out...")
                      yield self.__speech_converter_params["audio_data"]
  
              # Process user speech with ASR
              str = self.__speech_converter(**self.__speech_converter_params)
              yield str
  </code></pre>