|
|
|
@ -13,7 +13,7 @@ class InputBox: |
|
|
|
|
self._last_key_pressed = 0 |
|
|
|
|
self._key_press_time = 0 |
|
|
|
|
self._repeat_delay = 30 |
|
|
|
|
self._repeat_rate = 5 |
|
|
|
|
self._repeat_rate = 4 |
|
|
|
|
|
|
|
|
|
@property |
|
|
|
|
def text(self): |
|
|
|
@ -119,22 +119,29 @@ class InputBox: |
|
|
|
|
self.set_cursor_position(0) |
|
|
|
|
|
|
|
|
|
def _handle_keyboard_input(self): |
|
|
|
|
"""Process keyboard input.""" |
|
|
|
|
# Handle navigation keys |
|
|
|
|
key = rl.get_key_pressed() |
|
|
|
|
if key != 0: |
|
|
|
|
self._process_key(key) |
|
|
|
|
if key in (rl.KEY_LEFT, rl.KEY_RIGHT, rl.KEY_BACKSPACE, rl.KEY_DELETE): |
|
|
|
|
self._last_key_pressed = key |
|
|
|
|
self._key_press_time = 0 |
|
|
|
|
|
|
|
|
|
# Handle key repeats |
|
|
|
|
if key == self._last_key_pressed and key != 0: |
|
|
|
|
# Handle repeats for held keys |
|
|
|
|
elif self._last_key_pressed != 0: |
|
|
|
|
if rl.is_key_down(self._last_key_pressed): |
|
|
|
|
self._key_press_time += 1 |
|
|
|
|
if self._key_press_time > self._repeat_delay and self._key_press_time % self._repeat_rate == 0: |
|
|
|
|
# Process repeated key |
|
|
|
|
pass |
|
|
|
|
self._process_key(self._last_key_pressed) |
|
|
|
|
else: |
|
|
|
|
return # Skip processing until repeat triggers |
|
|
|
|
else: |
|
|
|
|
self._last_key_pressed = key |
|
|
|
|
self._key_press_time = 0 |
|
|
|
|
self._last_key_pressed = 0 |
|
|
|
|
|
|
|
|
|
# Handle navigation keys |
|
|
|
|
# Handle text input |
|
|
|
|
char = rl.get_char_pressed() |
|
|
|
|
if char != 0 and char >= 32: # Filter out control characters |
|
|
|
|
self.add_char_at_cursor(chr(char)) |
|
|
|
|
|
|
|
|
|
def _process_key(self, key): |
|
|
|
|
if key == rl.KEY_LEFT: |
|
|
|
|
if self._cursor_position > 0: |
|
|
|
|
self.set_cursor_position(self._cursor_position - 1) |
|
|
|
@ -149,8 +156,3 @@ class InputBox: |
|
|
|
|
self.set_cursor_position(0) |
|
|
|
|
elif key == rl.KEY_END: |
|
|
|
|
self.set_cursor_position(len(self._input_text)) |
|
|
|
|
|
|
|
|
|
# Handle text input |
|
|
|
|
char = rl.get_char_pressed() |
|
|
|
|
if char != 0 and char >= 32: # Filter out control characters |
|
|
|
|
self.add_char_at_cursor(chr(char)) |
|
|
|
|