接受python线程中的键盘输入

时间:2018-08-15 09:57:05

标签: python-3.x keyboard-events

我在Ubuntu 18.04上将python3与GStreamer一起使用。 我有一个特定的用例,其中我运行线程并为GStreamer元素设置某些属性。在某个按键上(例如s),我想设置另一个属性,该属性基本上会暂停GStreamer管道。在第二次按下时,我想再次恢复GStreamer管道。每次按键都会打开和关闭。

这是我的代码:

class ThreadingExample(object):
  def __init__(self):

    thread2 = threading.Thread(target=self.get)
    thread = threading.Thread(target=self.run)
    thread.daemon = True
    thread.start()
    thread2.start()


  def run(self):
            #obtain values from external device.

  def get(self):
     while True:
            # if no keyboard press, keep setting certain property for Gstreamer 
            Element X.The values are obtained from an external device, and a 
            daemon thread retrieves these values.

            # perform non blocking polling for keyboard input 's', after 2 seconds of daemon thread start.
            # if input is first 's', set to pause
            # if input is second 's',set to replay

link解释了我们可以执行的某些方法,但没有一个对我有用。 我是python的新手,并且更习惯于C / C ++编程。这种情况在C / C ++中要容易得多,在这里我可以编写一个共享库并在python中使用它。但是我想学习python,因此试图以一种更简单的方式找到它的新方法。

有人能解决这个问题吗?

0 个答案:

没有答案