我的软件有问题。在我的钢琴软件中,如果我一直按下键盘上的一个键,那么它就会重复多次重复该特定键的相同音调。但实际上我需要一个单一的音调,直到释放那个特定的键。我提供了一部分代码来检测 keyPress 事件并调用相应的方法。那么我必须对我的代码进行哪些更改??
def keyPressEvent(self, event):
if type(event) == QtGui.QKeyEvent and event.key() == QtCore.Qt.Key_A :
self.Playnote('/home/hemanth/hemanth/Piano/C.mp3')
self.ui.pushButton.animateClick(100)
if type(event) == QtGui.QKeyEvent and event.key() == QtCore.Qt.Key_S:
self.Playnote('/home/hemanth/hemanth/Piano/D.mp3')
self.ui.pushButton_2.animateClick(100)
最佳答案
你应该检查event.isAutoRepeat()
以确定事件是由键盘自动重复还是实际按键引起的。如果是自动重复,请忽略该按。
关于python - PyQt 中的 QKeyPress 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10046945/