Apply CB on keyboard

Hi,
I presented this problem yesterday but I deleted it because I wanted to give it another try.
I’m trying to handle the apply cb from the keyboard.

I have been monitoring the events and I don’t get the apply event. I might be that I have to read if the apply even has been triggered and is not like the click one.

I rode the callback documentation several times but I don’t get it.

Can someone give me a hand?

Many thanks.

Hi @Claudio_Gil!
Please send us the code wrote that is trying to use callbacks.
We need to see what you are trying to do, because your question is too general.

1 Like

I just want to do an if when the apply button is pressed.

def event_handler(obj, event):
if event == lv.EVENT.APPLY:
print(“OK”)

I also where printing the events:
def event_handlerkb(obj, event):
print(“Key:”, lv.EVENT.KEY)
print(“Event:”, event)
print("|||||||||||||||||||||||||||||||||||||||||||||||||||")
if event == lv.EVENT.APPLY:
print(“Lets go”)

Where do you register the callback?
Please send a complete script that we could run on our side.

I’m not registering the callback, that might be the problem…
I didn’t found a fully working example so I can see how the callbacks are being handled.
Do you have any example? I might be missing the right documentation.

I don’t understand what you are trying to do.
Please explain

  • What platform are you running LVGL on?
  • What drivers do you use?
  • Do you want to receive event from a specific driver? Or are you trying to write your own driver?

I’m running LVGL on a Onion omega dash.
Here is the all the code related with the driver.
Sorry but I’m a little bit lost with LVGL.

import lvgl as lv

lv.init()
import fb

fb.init()
symbolstyle = lv.style_t(lv.style_plain)
disp_buf1 = lv.disp_buf_t()
buf1_1 = bytearray(320 * 10)
lv.disp_buf_init(disp_buf1, buf1_1, None, len(buf1_1) // 4)

disp_drv = lv.disp_drv_t()
lv.disp_drv_init(disp_drv)
disp_drv.buffer = disp_buf1
disp_drv.flush_cb = fb.flush

disp_drv.hor_res = fb.fill

disp_drv.ver_res = fb.map

lv.disp_drv_register(disp_drv)

import xpt7603

touch = xpt7603.xpt7603()
touch.init()

indev_drv = lv.indev_drv_t()
lv.indev_drv_init(indev_drv)
indev_drv.type = lv.INDEV_TYPE.POINTER;
indev_drv.read_cb = touch.read;
lv.indev_drv_register(indev_drv);

Load the screen

scr = lv.obj()
lv.scr_load(scr)

Thank you for posting a complete code.

I see you don’t register any keyboard driver.
Without a keyboard driver you will not be able to detect key press.
I didn’t know it was possible to attach a keyboard to the Omega Dash. Do you attach it through USB?

I’m using the virtual keyboard, sorry, I think I should pointed that. I didn’t think on the possibility of an USB keyboard.
My code is just the keyboard example buy I added the cb event

if testkeyboard:
# Create styles for the keyboard
rel_style = lv.style_t()
pr_style = lv.style_t()

lv.style_copy(rel_style, lv.style_btn_rel)
rel_style.body.radius = 0
rel_style.body.border.width = 1

lv.style_copy(pr_style, lv.style_btn_pr)
pr_style.body.radius = 0
pr_style.body.border.width = 1

# Create a keyboard and apply the styles
kb = lv.kb(lv.scr_act())
kb.set_cursor_manage(True)
kb.set_style(lv.kb.STYLE.BG, lv.style_transp_tight)
kb.set_style(lv.kb.STYLE.BTN_REL, rel_style)
kb.set_style(lv.kb.STYLE.BTN_PR, pr_style)
kb.set_event_cb(event_handlerkb)  <-----Here is the cb I added
# Create a text area. The keyboard will write here
ta = lv.ta(lv.scr_act())
ta.align(None, lv.ALIGN.IN_TOP_MID, 0, 10)
ta.set_text("")

# Assign the text area to the keyboard
kb.set_ta(ta)

I hope you understand now how important it is to send the full script, not just pieces of it.

Here is an online example, based on your script, with an event handler.

https://sim.lvgl.io/micropython/ports/javascript/bundle_out/index.html?script_direct=77ac3bff46460ecf63a997323f69ddff8faea609

When you click the ✓ symbol, it prints “OK!”

Many thanks Amirgon. I have been bussy all the day, sorry for my late response and sorry for not sending all the code from the start. I was trying a lot of different widgets and my code where a little bit untidy. Next time I’ll shove together all the code related with the problem and post it.

Thank you again, have a nice day :slight_smile:

1 Like