@@ -56,6 +56,9 @@ def __init__(self, parent):
5656 # Create underlying LVGL keyboard widget
5757 self ._keyboard = lv .keyboard (parent )
5858
59+ # Store textarea reference (we DON'T pass it to LVGL to avoid double-typing)
60+ self ._textarea = None
61+
5962 # Configure layouts
6063 self ._setup_layouts ()
6164
@@ -118,12 +121,21 @@ def _handle_events(self, event):
118121 Args:
119122 event: LVGL event object
120123 """
124+ # Only process VALUE_CHANGED events
125+ event_code = event .get_code ()
126+ if event_code != lv .EVENT .VALUE_CHANGED :
127+ return
128+
121129 # Get the pressed button and its text
122130 button = self ._keyboard .get_selected_button ()
123131 text = self ._keyboard .get_button_text (button )
124132
125- # Get current textarea content
126- ta = self ._keyboard .get_textarea ()
133+ # Ignore if no valid button text (can happen during initialization)
134+ if text is None :
135+ return
136+
137+ # Get current textarea content (from our own reference, not LVGL's)
138+ ta = self ._textarea
127139 if not ta :
128140 return
129141
@@ -179,6 +191,31 @@ def _handle_events(self, event):
179191 # Update textarea
180192 ta .set_text (new_text )
181193
194+ def set_textarea (self , textarea ):
195+ """
196+ Set the textarea that this keyboard types into.
197+
198+ IMPORTANT: We store the textarea reference ourselves and DON'T pass
199+ it to the underlying LVGL keyboard. This prevents LVGL's built-in
200+ automatic character insertion, which would cause double-character bugs
201+ (LVGL inserts + our handler inserts = double characters).
202+
203+ Args:
204+ textarea: The lv.textarea widget to type into, or None to disconnect
205+ """
206+ self ._textarea = textarea
207+ # NOTE: We deliberately DO NOT call self._keyboard.set_textarea()
208+ # to avoid LVGL's automatic character insertion
209+
210+ def get_textarea (self ):
211+ """
212+ Get the textarea that this keyboard types into.
213+
214+ Returns:
215+ The lv.textarea widget, or None if not connected
216+ """
217+ return self ._textarea
218+
182219 def set_mode (self , mode ):
183220 """
184221 Set keyboard mode with proper map configuration.
0 commit comments