PDA

View Full Version : Key event problems



QT_NUB
1st January 2016, 00:21
Hey And Happy New Year! :cool:

I'm doing little 2D game with PyQt5. This game can be played in 2-4 player group at the same time and on the same keyboard. Every player has own four keys for moving UP/DOWN/LEFT/RIGHT.

Here are the questions:

Is it possible to handle many same time pressed keys in PyQt5? e.g. I'm having two players with their own keys. I want to press UP and RIGHT buttons on both players at the same time. Both players should move to north-east at the same time.

Is it possible to remove the time gap between very first key press and AutoRepeat? I want it to repeat the key event from very beginning of the key press without any little stops (That stop takes about 200ms but it's very notable stop in the game where players should move smoothly).

anda_skoa
1st January 2016, 12:54
Key events are fired independently, so you just need to modify your state whenever one happens.

Instead of auto repeat I would just toggle on key press / release and use a timer for "repeat".

Cheers,
_

QT_NUB
1st January 2016, 14:25
Actually one more question :D

Can each QGraphicsItem (player) handle own events in own event side? Is it possible to focus on two event sides at the same time? e.g. There are two players, so there are two QGraphicsItems and both QGraphicsItem has keyPressEvent and keyReleaseEvent. Can their events be handled as separated ones or do I have to get them to one side? I tried this little bit but just one of them moved.

The EYE
11th January 2016, 07:27
Hey QT_NUB,

it woukd be usefull to see some code ;-)

Max

anda_skoa
11th January 2016, 09:05
Can each QGraphicsItem (player) handle own events in own event side?

While each item could implement its own event handling, only one would receive key events at any given time (i.e. would have the keyboard focus).

What you need instead is event handling at the scene level.

Cheers,
_