Button Event
- When operating buttons and encoders, LVGL will generate lv for the currently focused control EVENT KEY events and corresponding key codes, the key codes corresponding to different operations are as follows:
Operation | LVGL key code |
---|---|
Encoder rotates clockwise(down) | lv.KEY.LEFT |
Encoder rotates counter-clockwise(up) | lv.KEY.RIGHT |
Press encoder | lv.KEY.ENTER |
Press the ESC button | lv.KEY.ESC |
- Example
def event_handler(e): e_key = e.get_key() if e_key == lv.KEY.RIGHT: print("up") elif e_key == lv.KEY.LEFT: print("down") elif e_key == lv.KEY.ENTER: print("enter") elif e_key == lv.KEY.ESC: print("esc") scr.add_event(event_handler, lv.EVENT.ALL, None)