1
1
"""sshkeyboard"""
2
2
3
- __version__ = "0.0.1 "
3
+ __version__ = "0.1.0 "
4
4
5
5
import asyncio
6
6
import concurrent .futures
@@ -110,9 +110,9 @@ def listen_keyboard(
110
110
on_press : Optional [Callable [[str ], Any ]] = None ,
111
111
on_release : Optional [Callable [[str ], Any ]] = None ,
112
112
until : str = "esc" ,
113
- sequental : bool = False ,
113
+ sequential : bool = False ,
114
114
delay_second_char : float = 0.75 ,
115
- delay_others : float = 0.05 ,
115
+ delay_other_chars : float = 0.05 ,
116
116
lower : bool = True ,
117
117
debug : bool = False ,
118
118
max_thread_pool_workers : Optional [int ] = None ,
@@ -141,21 +141,21 @@ def press(key):
141
141
on_release: Function that gets called when a key is released. The
142
142
function takes the released key as parameter. Defaults to None.
143
143
until: A key that will end keyboard listening. Defaults to "esc".
144
- sequental : If enabled, callbacks will be forced to happen one by
144
+ sequential : If enabled, callbacks will be forced to happen one by
145
145
one instead of concurrently. Defaults to False.
146
146
delay_second_char: The timeout between first and second character when
147
147
holding down a key. Depends on terminal and is used for parsing
148
148
the input. Defaults to 0.75.
149
- delay_others : The timeout between all other characters when holding
150
- down a key. Depends on terminal and is used for parsing the input.
151
- Defaults to 0.05.
149
+ delay_other_chars : The timeout between all other characters when
150
+ holding down a key. Depends on terminal and is used for parsing
151
+ the input. Defaults to 0.05.
152
152
lower: If enabled, the callback 'key' parameter gets turned into lower
153
153
case key even if it was upper case, for example "A" -> "a".
154
154
Defaults to True.
155
155
debug: Print debug messages. Defaults to False.
156
156
max_thread_pool_workers: Define the number of workers in
157
157
ThreadPoolExecutor, None means that a default value will get used.
158
- Will get ignored if sequental =True. Defaults to None.
158
+ Will get ignored if sequential =True. Defaults to None.
159
159
"""
160
160
161
161
assert not asyncio .iscoroutinefunction (
@@ -170,9 +170,9 @@ def press(key):
170
170
on_press ,
171
171
on_release ,
172
172
until ,
173
- sequental ,
173
+ sequential ,
174
174
delay_second_char ,
175
- delay_others ,
175
+ delay_other_chars ,
176
176
lower ,
177
177
debug ,
178
178
max_thread_pool_workers ,
@@ -185,9 +185,9 @@ def listen_keyboard_async(
185
185
on_press : Optional [Callable [[str ], Any ]] = None ,
186
186
on_release : Optional [Callable [[str ], Any ]] = None ,
187
187
until : str = "esc" ,
188
- sequental : bool = False ,
188
+ sequential : bool = False ,
189
189
delay_second_char : float = 0.75 ,
190
- delay_others : float = 0.05 ,
190
+ delay_other_chars : float = 0.05 ,
191
191
lower : bool = True ,
192
192
debug : bool = False ,
193
193
max_thread_pool_workers : Optional [int ] = None ,
@@ -200,7 +200,7 @@ def listen_keyboard_async(
200
200
The new parameter `sleep` defines a timeout between starting the
201
201
callbacks.
202
202
203
- For the asynchronous callbacks, parameter `sequental ` defines whether a
203
+ For the asynchronous callbacks, parameter `sequential ` defines whether a
204
204
callback is awaited or not before starting the next callback.
205
205
206
206
Example:
@@ -220,21 +220,21 @@ async def press(key):
220
220
on_release: Function that gets called when a key is released. The
221
221
function takes the released key as parameter. Defaults to None.
222
222
until: A key that will end keyboard listening. Defaults to "esc".
223
- sequental : If enabled, callbacks will be forced to happen one by
223
+ sequential : If enabled, callbacks will be forced to happen one by
224
224
one instead of concurrently. Defaults to False.
225
225
delay_second_char: The timeout between first and second character when
226
226
holding down a key. Depends on terminal and is used for parsing
227
227
the input. Defaults to 0.75.
228
- delay_others : The timeout between all other characters when holding
229
- down a key. Depends on terminal and is used for parsing the input.
230
- Defaults to 0.05.
228
+ delay_other_chars : The timeout between all other characters when
229
+ holding down a key. Depends on terminal and is used for parsing
230
+ the input. Defaults to 0.05.
231
231
lower: If enabled, the callback 'key' parameter gets turned into lower
232
232
case key even if it was upper case, for example "A" -> "a".
233
233
Defaults to True.
234
234
debug: Print debug messages. Defaults to False.
235
235
max_thread_pool_workers: Define the number of workers in
236
236
ThreadPoolExecutor, None means that a default value will get used.
237
- Will get ignored if sequental =True. Defaults to None.
237
+ Will get ignored if sequential =True. Defaults to None.
238
238
sleep: asyncio.sleep() amount between starting the callbacks. None
239
239
will remove the sleep altogether. Defaults to 0.05.
240
240
"""
@@ -244,9 +244,9 @@ async def press(key):
244
244
on_press ,
245
245
on_release ,
246
246
until ,
247
- sequental ,
247
+ sequential ,
248
248
delay_second_char ,
249
- delay_others ,
249
+ delay_other_chars ,
250
250
lower ,
251
251
debug ,
252
252
max_thread_pool_workers ,
@@ -259,9 +259,9 @@ async def listen_keyboard_async_manual(
259
259
on_press : Optional [Callable [[str ], Any ]] = None ,
260
260
on_release : Optional [Callable [[str ], Any ]] = None ,
261
261
until : str = "esc" ,
262
- sequental : bool = False ,
262
+ sequential : bool = False ,
263
263
delay_second_char : float = 0.75 ,
264
- delay_others : float = 0.05 ,
264
+ delay_other_chars : float = 0.05 ,
265
265
lower : bool = True ,
266
266
debug : bool = False ,
267
267
max_thread_pool_workers : Optional [int ] = None ,
@@ -301,13 +301,13 @@ async def listen_keyboard_async_manual(
301
301
_check_callback_ok (on_press , "on_press" )
302
302
_check_callback_ok (on_release , "on_release" )
303
303
assert isinstance (until , str ), "'until' has to be a string"
304
- assert isinstance (sequental , bool ), "'sequental ' has to be boolean"
304
+ assert isinstance (sequential , bool ), "'sequential ' has to be boolean"
305
305
assert isinstance (
306
306
delay_second_char , (int , float )
307
307
), "'delay_second_char' has to be numeric"
308
308
assert isinstance (
309
- delay_others , (int , float )
310
- ), "'delay_others ' has to be numeric"
309
+ delay_other_chars , (int , float )
310
+ ), "'delay_other_chars ' has to be numeric"
311
311
assert isinstance (lower , bool ), "'lower' has to be boolean"
312
312
assert isinstance (debug , bool ), "'debug' has to be boolean"
313
313
assert max_thread_pool_workers is None or isinstance (
@@ -322,7 +322,7 @@ async def listen_keyboard_async_manual(
322
322
323
323
# Create thread pool executor only if it will get used
324
324
executor = None
325
- if not sequental and (
325
+ if not sequential and (
326
326
not asyncio .iscoroutinefunction (on_press )
327
327
or not asyncio .iscoroutinefunction (on_release )
328
328
):
@@ -333,11 +333,11 @@ async def listen_keyboard_async_manual(
333
333
# Package parameters into namespaces so they are easier to pass around
334
334
# Options do not change
335
335
options = SimpleNamespace (
336
- on_press_callback = _callback (on_press , sequental , executor ),
337
- on_release_callback = _callback (on_release , sequental , executor ),
336
+ on_press_callback = _callback (on_press , sequential , executor ),
337
+ on_release_callback = _callback (on_release , sequential , executor ),
338
338
until = until ,
339
339
delay_second_char = delay_second_char ,
340
- delay_others = delay_others ,
340
+ delay_other_chars = delay_other_chars ,
341
341
lower = lower ,
342
342
debug = debug ,
343
343
)
@@ -416,12 +416,12 @@ def _done(task):
416
416
_should_run = False
417
417
418
418
419
- def _callback (cb_function , sequental , executor ):
419
+ def _callback (cb_function , sequential , executor ):
420
420
async def _cb (key ):
421
421
if cb_function is None :
422
422
return
423
423
424
- if sequental :
424
+ if sequential :
425
425
if asyncio .iscoroutinefunction (cb_function ):
426
426
await cb_function (key )
427
427
else :
@@ -531,7 +531,7 @@ async def _react_to_input(state, options):
531
531
# - The second character comes slower than the rest on terminal
532
532
elif state .previous != "" and (
533
533
time () - state .initial_press_time > options .delay_second_char
534
- and time () - state .press_time > options .delay_others
534
+ and time () - state .press_time > options .delay_other_chars
535
535
):
536
536
await options .on_release_callback (state .previous )
537
537
state .previous = state .current
0 commit comments