最近,我开始研究一个小型用户交互程序,它收集用户鼠标点击并执行一些操作。我想知道如何将鼠标作为一个设备,与QT一起对待,并捕获它的左,右和中间点击,并结束到这个类。
class UserInputProcessor:
@abc.abstractmethod
def process_user_input(self):
pass
以下是我为macrophone进行语音识别所做的事情:
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
答案 0 :(得分:0)
这是我发现的鼠标输入
selector = selectors.DefaultSelector()
mouse = evdev.InputDevice('/dev/input/event16')
keybd = evdev.InputDevice('/dev/input/event11')
# This works because InputDevice has a `fileno()` method.
selector.register(mouse, selectors.EVENT_READ)
selector.register(keybd, selectors.EVENT_READ)
while True:
for key, mask in selector.select():
device = key.fileobj
for event in device.read():
if event.value == 589825:
print ("left button")
elif event.value == 589827:
print ("middle button")
elif event.value == 589826:
print ("right button")