Skip to content

Commit a09e100

Browse files
committed
Version changed to 0.1.0, changelog updated
Some parameter names changed
1 parent 8b4be28 commit a09e100

File tree

4 files changed

+64
-42
lines changed

4 files changed

+64
-42
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ using with headless computers/servers or for example inside Windows Subsystem
1111
for Linux (WSL 2). One good use case is Raspberry Pi with Raspberry
1212
Pi OS Lite.
1313

14-
Supports asyncio and sequental/concurrent callback modes. For Python versions
14+
Supports asyncio and sequential/concurrent callback modes. For Python versions
1515
above 3.7.
1616

1717
[Documentation](https://sshkeyboard.readthedocs.io)
@@ -72,7 +72,7 @@ with some **limitations**, mainly:
7272

7373
## Advanced use
7474

75-
### Sequental mode
75+
### Sequential mode
7676

7777
Normally this library allows `on_press` and `on_release` callback to be run
7878
concurrently. This means that by running:
@@ -101,11 +101,11 @@ and pressing `a`, `s` and `d` keys will log:
101101
```
102102

103103
But sometimes you don't want to allow the callbacks to overlap, then
104-
you should set `sequental` parameter to `True`:
104+
you should set `sequential` parameter to `True`:
105105

106106
```python
107107
# ...
108-
listen_keyboard(on_press=press, sequental=True)
108+
listen_keyboard(on_press=press, sequential=True)
109109
```
110110

111111
will log:
@@ -179,11 +179,11 @@ Pressing `a` and `s` will log:
179179
's' release slept
180180
```
181181

182-
And with `sequental=True`:
182+
And with `sequential=True`:
183183

184184
```python
185185
# ...
186-
listen_keyboard_async(on_press=press, on_release=release, sequental=True)
186+
listen_keyboard_async(on_press=press, on_release=release, sequential=True)
187187
```
188188

189189
will log:
@@ -240,7 +240,7 @@ you can try to tweak the default timing parameters:
240240

241241
```python
242242
# ...
243-
listen_keyboard(on_press=press, delay_second_char=0.75, delay_others=0.05)
243+
listen_keyboard(on_press=press, delay_second_char=0.75, delay_other_chars=0.05)
244244
```
245245

246246
### More

docs/source/changelog.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
1-
# Changelog
1+
# Changelog
2+
3+
## 0.1.0
4+
5+
Initial release for testing. Main functionality working but requires more testing.
6+
7+
Supported functions:
8+
9+
- listen_keyboard
10+
- listen_keyboard_async
11+
- listen_keyboard_async_manual
12+
13+
`listen_keyboard_async` supported parameters:
14+
15+
- on_press
16+
- on_release
17+
- until
18+
- sequential
19+
- delay_second_char
20+
- delay_other_chars
21+
- lower
22+
- debug
23+
- max_thread_pool_workers
24+
- sleep

src/sshkeyboard.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""sshkeyboard"""
22

3-
__version__ = "0.0.1"
3+
__version__ = "0.1.0"
44

55
import asyncio
66
import concurrent.futures
@@ -110,9 +110,9 @@ def listen_keyboard(
110110
on_press: Optional[Callable[[str], Any]] = None,
111111
on_release: Optional[Callable[[str], Any]] = None,
112112
until: str = "esc",
113-
sequental: bool = False,
113+
sequential: bool = False,
114114
delay_second_char: float = 0.75,
115-
delay_others: float = 0.05,
115+
delay_other_chars: float = 0.05,
116116
lower: bool = True,
117117
debug: bool = False,
118118
max_thread_pool_workers: Optional[int] = None,
@@ -141,21 +141,21 @@ def press(key):
141141
on_release: Function that gets called when a key is released. The
142142
function takes the released key as parameter. Defaults to None.
143143
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
145145
one instead of concurrently. Defaults to False.
146146
delay_second_char: The timeout between first and second character when
147147
holding down a key. Depends on terminal and is used for parsing
148148
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.
152152
lower: If enabled, the callback 'key' parameter gets turned into lower
153153
case key even if it was upper case, for example "A" -> "a".
154154
Defaults to True.
155155
debug: Print debug messages. Defaults to False.
156156
max_thread_pool_workers: Define the number of workers in
157157
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.
159159
"""
160160

161161
assert not asyncio.iscoroutinefunction(
@@ -170,9 +170,9 @@ def press(key):
170170
on_press,
171171
on_release,
172172
until,
173-
sequental,
173+
sequential,
174174
delay_second_char,
175-
delay_others,
175+
delay_other_chars,
176176
lower,
177177
debug,
178178
max_thread_pool_workers,
@@ -185,9 +185,9 @@ def listen_keyboard_async(
185185
on_press: Optional[Callable[[str], Any]] = None,
186186
on_release: Optional[Callable[[str], Any]] = None,
187187
until: str = "esc",
188-
sequental: bool = False,
188+
sequential: bool = False,
189189
delay_second_char: float = 0.75,
190-
delay_others: float = 0.05,
190+
delay_other_chars: float = 0.05,
191191
lower: bool = True,
192192
debug: bool = False,
193193
max_thread_pool_workers: Optional[int] = None,
@@ -200,7 +200,7 @@ def listen_keyboard_async(
200200
The new parameter `sleep` defines a timeout between starting the
201201
callbacks.
202202
203-
For the asynchronous callbacks, parameter `sequental` defines whether a
203+
For the asynchronous callbacks, parameter `sequential` defines whether a
204204
callback is awaited or not before starting the next callback.
205205
206206
Example:
@@ -220,21 +220,21 @@ async def press(key):
220220
on_release: Function that gets called when a key is released. The
221221
function takes the released key as parameter. Defaults to None.
222222
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
224224
one instead of concurrently. Defaults to False.
225225
delay_second_char: The timeout between first and second character when
226226
holding down a key. Depends on terminal and is used for parsing
227227
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.
231231
lower: If enabled, the callback 'key' parameter gets turned into lower
232232
case key even if it was upper case, for example "A" -> "a".
233233
Defaults to True.
234234
debug: Print debug messages. Defaults to False.
235235
max_thread_pool_workers: Define the number of workers in
236236
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.
238238
sleep: asyncio.sleep() amount between starting the callbacks. None
239239
will remove the sleep altogether. Defaults to 0.05.
240240
"""
@@ -244,9 +244,9 @@ async def press(key):
244244
on_press,
245245
on_release,
246246
until,
247-
sequental,
247+
sequential,
248248
delay_second_char,
249-
delay_others,
249+
delay_other_chars,
250250
lower,
251251
debug,
252252
max_thread_pool_workers,
@@ -259,9 +259,9 @@ async def listen_keyboard_async_manual(
259259
on_press: Optional[Callable[[str], Any]] = None,
260260
on_release: Optional[Callable[[str], Any]] = None,
261261
until: str = "esc",
262-
sequental: bool = False,
262+
sequential: bool = False,
263263
delay_second_char: float = 0.75,
264-
delay_others: float = 0.05,
264+
delay_other_chars: float = 0.05,
265265
lower: bool = True,
266266
debug: bool = False,
267267
max_thread_pool_workers: Optional[int] = None,
@@ -301,13 +301,13 @@ async def listen_keyboard_async_manual(
301301
_check_callback_ok(on_press, "on_press")
302302
_check_callback_ok(on_release, "on_release")
303303
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"
305305
assert isinstance(
306306
delay_second_char, (int, float)
307307
), "'delay_second_char' has to be numeric"
308308
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"
311311
assert isinstance(lower, bool), "'lower' has to be boolean"
312312
assert isinstance(debug, bool), "'debug' has to be boolean"
313313
assert max_thread_pool_workers is None or isinstance(
@@ -322,7 +322,7 @@ async def listen_keyboard_async_manual(
322322

323323
# Create thread pool executor only if it will get used
324324
executor = None
325-
if not sequental and (
325+
if not sequential and (
326326
not asyncio.iscoroutinefunction(on_press)
327327
or not asyncio.iscoroutinefunction(on_release)
328328
):
@@ -333,11 +333,11 @@ async def listen_keyboard_async_manual(
333333
# Package parameters into namespaces so they are easier to pass around
334334
# Options do not change
335335
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),
338338
until=until,
339339
delay_second_char=delay_second_char,
340-
delay_others=delay_others,
340+
delay_other_chars=delay_other_chars,
341341
lower=lower,
342342
debug=debug,
343343
)
@@ -416,12 +416,12 @@ def _done(task):
416416
_should_run = False
417417

418418

419-
def _callback(cb_function, sequental, executor):
419+
def _callback(cb_function, sequential, executor):
420420
async def _cb(key):
421421
if cb_function is None:
422422
return
423423

424-
if sequental:
424+
if sequential:
425425
if asyncio.iscoroutinefunction(cb_function):
426426
await cb_function(key)
427427
else:
@@ -531,7 +531,7 @@ async def _react_to_input(state, options):
531531
# - The second character comes slower than the rest on terminal
532532
elif state.previous != "" and (
533533
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
535535
):
536536
await options.on_release_callback(state.previous)
537537
state.previous = state.current

tests/test_sshkeyboard.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,4 @@ def ok4(key="a", key2="s"):
115115
sshkeyboard.listen_keyboard(ok4, stops)
116116

117117

118-
# TODO, assert async fails listen, test sleeps,
119-
# schedule orders, throwing errors etc.
118+
# TODO add tests for: sleeps and print orders, throwing errors, assertions

0 commit comments

Comments
 (0)