@@ -91,9 +91,10 @@ class TextInput(Widget):
91
91
:param onselect: Function when selecting the widget
92
92
:param password: Input string is displayed as a password
93
93
:param password_char: Character used by password type
94
- :param repeat_keys_initial_ms: Time in ms before keys are repeated when held in ms
95
- :param repeat_keys_interval_ms: Interval between key press repetition when held in ms
96
- :param repeat_mouse_interval_ms: Interval between mouse events when held in ms
94
+ :param repeat_keys: Enable key repeat
95
+ :param repeat_keys_initial_ms: Time in milliseconds before keys are repeated when held in milliseconds
96
+ :param repeat_keys_interval_ms: Interval between key press repetition when held in milliseconds
97
+ :param repeat_mouse_interval_ms: Interval between mouse events when held in milliseconds
97
98
:param text_ellipsis: Ellipsis text when overflow occurs (input length exceeds maxwidth)
98
99
:param valid_chars: List of chars that are valid, ``None`` if all chars are valid
99
100
:param kwargs: Optional keyword arguments
@@ -130,6 +131,7 @@ class TextInput(Widget):
130
131
_input_underline_vmargin : int
131
132
_key_is_pressed : bool
132
133
_keychar_size : Dict [str , NumberType ]
134
+ _keyrepeat : bool
133
135
_keyrepeat_counters : Dict [int , List [int ]]
134
136
_keyrepeat_initial_interval_ms : NumberType
135
137
_keyrepeat_interval_ms : NumberType
@@ -181,6 +183,7 @@ def __init__(
181
183
onselect : CallbackType = None ,
182
184
password : bool = False ,
183
185
password_char : str = '*' ,
186
+ repeat_keys : bool = True ,
184
187
repeat_keys_initial_ms : NumberType = 400 ,
185
188
repeat_keys_interval_ms : NumberType = 50 ,
186
189
repeat_mouse_interval_ms : NumberType = 400 ,
@@ -202,6 +205,7 @@ def __init__(
202
205
assert isinstance (maxwidth , int )
203
206
assert isinstance (password , bool )
204
207
assert isinstance (password_char , str )
208
+ assert isinstance (repeat_keys , bool )
205
209
assert isinstance (repeat_keys_initial_ms , NumberInstance )
206
210
assert isinstance (repeat_keys_interval_ms , NumberInstance )
207
211
assert isinstance (repeat_mouse_interval_ms , NumberInstance )
@@ -222,11 +226,11 @@ def __init__(
222
226
assert cursor_switch_ms > 0 , \
223
227
'cursor switch in milliseconds must be greater than zero'
224
228
assert repeat_keys_initial_ms > 0 , \
225
- 'ms cannot be lower or equal than zero'
229
+ 'repeat keys initial ms cannot be lower or equal than zero'
226
230
assert repeat_keys_interval_ms > 0 , \
227
- 'ms cannot be lower or equal than zero'
231
+ 'repeat keys interval ms cannot be lower or equal than zero'
228
232
assert repeat_mouse_interval_ms > 0 , \
229
- 'ms cannot be lower or equal than zero'
233
+ 'repeat mouse interval ms cannot be lower or equal than zero'
230
234
231
235
cursor_color = assert_color (cursor_color )
232
236
cursor_selection_color = assert_color (cursor_selection_color )
@@ -273,6 +277,7 @@ def __init__(
273
277
# Vars to make keydown repeat after user pressed a key for some time:
274
278
self ._block_copy_paste = False # Blocks event
275
279
self ._key_is_pressed = False
280
+ self ._keyrepeat = repeat_keys
276
281
self ._keyrepeat_counters = {} # {event.key: (counter_int, event.unicode)} (look for "***")
277
282
self ._keyrepeat_initial_interval_ms = repeat_keys_initial_ms
278
283
self ._keyrepeat_interval_ms = repeat_keys_interval_ms
@@ -1877,22 +1882,23 @@ def update(self, events: EventVectorType) -> bool:
1877
1882
pos = pygame .mouse .get_pos ()
1878
1883
self ._check_mouse_collide_input ((pos [0 ], pos [1 ]))
1879
1884
1880
- # Update key counters:
1881
- for key in self ._keyrepeat_counters :
1882
- self ._keyrepeat_counters [key ][0 ] += time_clock # Update clock
1883
-
1884
- # Generate new key events if enough time has passed:
1885
- if self ._keyrepeat_counters [key ][0 ] >= self ._keyrepeat_initial_interval_ms :
1886
- self ._keyrepeat_counters [key ][0 ] = \
1887
- self ._keyrepeat_initial_interval_ms - self ._keyrepeat_interval_ms
1888
-
1889
- event_key , event_unicode = key , self ._keyrepeat_counters [key ][1 ]
1890
- self ._add_event (
1891
- pygame .event .Event (
1892
- pygame .KEYDOWN ,
1893
- key = event_key ,
1894
- unicode = event_unicode )
1895
- )
1885
+ # Update key counters
1886
+ if self ._keyrepeat :
1887
+ for key in self ._keyrepeat_counters :
1888
+ self ._keyrepeat_counters [key ][0 ] += time_clock # Update clock
1889
+
1890
+ # Generate new key events if enough time has passed:
1891
+ if self ._keyrepeat_counters [key ][0 ] >= self ._keyrepeat_initial_interval_ms :
1892
+ self ._keyrepeat_counters [key ][0 ] = \
1893
+ self ._keyrepeat_initial_interval_ms - self ._keyrepeat_interval_ms
1894
+
1895
+ event_key , event_unicode = key , self ._keyrepeat_counters [key ][1 ]
1896
+ self ._add_event (
1897
+ pygame .event .Event (
1898
+ pygame .KEYDOWN ,
1899
+ key = event_key ,
1900
+ unicode = event_unicode )
1901
+ )
1896
1902
1897
1903
return updated
1898
1904
@@ -1968,9 +1974,10 @@ def text_input(
1968
1974
- ``password_char`` (str) - Character used by password type. ``"*"`` by default
1969
1975
- ``readonly_color`` (tuple, list, str, int, :py:class:`pygame.Color`) – Color of the widget if readonly mode
1970
1976
- ``readonly_selected_color`` (tuple, list, str, int, :py:class:`pygame.Color`) – Color of the widget if readonly mode and is selected
1971
- - ``repeat_keys_initial_ms`` (int, float) - Time in ms before keys are repeated when held in ms. ``400`` by default
1972
- - ``repeat_keys_interval_ms`` (int, float) - Interval between key press repetition when held in ms. ``50`` by default
1973
- - ``repeat_mouse_interval_ms`` (int, float) - Interval between mouse events when held in ms. ``400`` by default
1977
+ - ``repeat_keys`` (bool) - Enable key repeat. ``True`` by default
1978
+ - ``repeat_keys_initial_ms`` (int, float) - Time in milliseconds before keys are repeated when held in milliseconds. ``400`` by default
1979
+ - ``repeat_keys_interval_ms`` (int, float) - Interval between key press repetition when held in milliseconds. ``50`` by default
1980
+ - ``repeat_mouse_interval_ms`` (int, float) - Interval between mouse events when held in milliseconds. ``400`` by default
1974
1981
- ``selection_color`` (tuple, list, str, int, :py:class:`pygame.Color`) – Color of the selected widget; only affects the font color
1975
1982
- ``selection_effect`` (:py:class:`pygame_menu.widgets.core.Selection`) – Widget selection effect
1976
1983
- ``shadow_color`` (tuple, list, str, int, :py:class:`pygame.Color`) – Color of the widget shadow
0 commit comments