AnalogSensePy 1.0.3__tar.gz → 1.0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: AnalogSensePy
3
- Version: 1.0.3
3
+ Version: 1.0.4
4
4
  Requires-Python: >=3.10
5
5
  License-File: LICENSE
6
6
  Requires-Dist: hidapi
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: AnalogSensePy
3
- Version: 1.0.3
3
+ Version: 1.0.4
4
4
  Requires-Python: >=3.10
5
5
  License-File: LICENSE
6
6
  Requires-Dist: hidapi
@@ -35,14 +35,35 @@ from analogsense import AnalogSense
35
35
 
36
36
  as_ = AnalogSense()
37
37
  devices = as_.get_devices()
38
- dev = devices[0]
38
+
39
+ if not devices:
40
+ print("no supported analog keyboards found.")
41
+ exit()
42
+
43
+ if len(devices) == 1:
44
+ dev = devices[0]
45
+ else:
46
+ for i, d in enumerate(devices):
47
+ print(f" [{i}] {d.product_name}")
48
+ dev = devices[int(input("select device index: "))]
39
49
 
40
50
  def on_keys(active_keys):
41
51
  for k in active_keys:
42
- print(as_.scancode_to_string(k["scancode"]), f"{k['value']:.2f}")
52
+ # converting the scancode to a nice readable string
53
+ name = as_.scancode_to_string(k["scancode"])
54
+
55
+ # some providers can return the digital state of the key
56
+ # (what the system perceives the key as pressed or not)
57
+ # other providers that do not support this will return None
58
+ if k["digital"] is not None:
59
+ digital = " [down]" if k["digital"] else " [up]"
60
+ else:
61
+ digital = ""
62
+
63
+ print(f"{name:20s} {k['value']:.4f}{digital}")
43
64
 
44
65
  dev.start_listening(on_keys)
45
- input("enter to stop...\n")
66
+ input("press keys... enter to stop.\n")
46
67
  dev.stop_listening()
47
68
  ```
48
69
 
@@ -4,6 +4,6 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "AnalogSensePy"
7
- version = "1.0.3"
7
+ version = "1.0.4"
8
8
  requires-python = ">=3.10"
9
9
  dependencies = ["hidapi"]
File without changes
File without changes