QKeyPress event in PyQt

0 votes
I am facing some trouble with my software. In my piano software if I keep pressing a key on the keyboard then it is making multiple repeated same tones of that particular key. But actually I need a single tone until the release of that particular key. I'm providing a part of my code that detects the keyPress event and calls the corresponding method. So what should be the changes that I've to do with my code??

def keyPressEvent(self, event):
    if type(event) == QtGui.QKeyEvent and event.key() == QtCore.Qt.Key_A :
    if type(event) == QtGui.QKeyEvent and event.key() == QtCore.Qt.Key_S:
May 2 in Python by ana1504.k
• 7,890 points

1 answer to this question.

0 votes
You should check event.isAutoRepeat() to determine if the event is caused by keyboard autorepeat or an actual keypress. If it is an autorepeat, ignore that press.
answered May 2 by SDeb
• 13,190 points

Related Questions In Python

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Question on PyQt: How to connect a signal to a slot to start a background operation in Python

It shouldn't matter whether the connection is ...READ MORE

answered Nov 27, 2018 in Python by Nymeria
• 3,520 points
+3 votes
7 answers

How can I rename a file in Python?

yes, you can use "os.rename" for that. ...READ MORE

answered Mar 31, 2018 in Python by DareDev
• 6,810 points
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 349 views
0 votes
1 answer

Indentation of Python in Notepad++

To indent the block, select the entire ...READ MORE

answered Sep 18, 2018 in Python by SDeb
• 13,190 points
0 votes
1 answer

Print C format in Python

For printf- style formatting and special case ...READ MORE

answered Sep 18, 2018 in Python by SDeb
• 13,190 points