Multiple keyboard keys / joystick repeat event? #333
-
Hi there, I am currently experimenting nicegui by building a simple 2D game with svg sprites. I had a lot of fun so far, nicegui is extremely satisfying to use! I tried both controlling my player with the keyboard and with a vitrual joystick - that works but I have a small issue in both cases:
I couldn't find any help about this in the documentation, but I must be missing something? Many thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Both elements fire events only when something changes. Key events are closely coupled to the corresponding JavaScript events: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent. They don't tell you what keys are currently pressed, but which key is changing its state, either down or up. If you need to know all currently pressed keys, you need to keep track of them yourself, unfortunately. The joystick behaves similarly: It only fires on change. Otherwise it would need to constantly send events at enormous (actually infinite) frequency. When implementing a game, you usually have some game loop that checks inputs and updates the output in regular intervals. You could, e.g., use a |
Beta Was this translation helpful? Give feedback.
Both elements fire events only when something changes. Key events are closely coupled to the corresponding JavaScript events: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent. They don't tell you what keys are currently pressed, but which key is changing its state, either down or up. If you need to know all currently pressed keys, you need to keep track of them yourself, unfortunately. The joystick behaves similarly: It only fires on change. Otherwise it would need to constantly send events at enormous (actually infinite) frequency.
When implementing a game, you usually have some game loop that checks inputs and updates the output in regular intervals. You could, e.g., use a
u…