Unix + SDL: How to get global Key Events and check for multiple keys being pressed at the same time?

Hello,

I am currently working on a project for Raspberry Pi and am using the Micropython LVGL port with SDL. I am trying to implement some global key event listeners which would trigger when a key is pressed independent from the current view.

I could successfully use the feedback_cb for the indev_drv but I am encountering following issue:

  1. I can’t really figuring out how to get a key_released event in micropython with SDL.keyboard_read (trying to retrieve event_data or casting the blob gives me the same event type)
  2. I am not sure what would be the best way to implement the listener in a way so I can trigger something pressing 2 keys at the same time

I saw in the docs that there is a way to achieve this by implementing the key callback method yourself (and using continue_read) but I am not happy to move away from the SDL.keyboard_read method.

I am very grateful for any help regarding this. I want to stay as vanilla LVGL as possible but am open for any idea. :slight_smile:

Hi @daviel !

The main issue here, is that current SDL driver implementation receives a string and sends it character by character.
It simulates a “key-down” to LVGL, followed by an immediate “key-up” for each character.

If it really handled key-down and key-up events, you could simply delegate the SDL driver through a custom driver and catch the events there.

Here is a simple simulation that shows how to do that:

https://sim.lvgl.io/v9.0/micropython/ports/javascript/index.html?script_direct=f1e7b7008363a47c9837289fe961a0bf8412143b

As you can see in the simulation, every keystroke generates both “Pressed” and “Released” event.

If you want, you can change the existing SDL driver to handle key-down/key-up events.
If you do, feel free to send us a PR. I think it would make more sense to really send key-down-up events instead of simulating them.

1 Like

Thank you very much for your feedback. I was able to get it working but encountered some weird situation with groups added in the mix.

I created a MR here where I described my issue in more detail: https://github.com/lvgl/lv_binding_micropython/pull/236