Skip to content

Commit 05f4fa6

Browse files
authored
fix: Wayland pynput v1.7.7 workaround (#106)
XWayland/Wayland does not reliably allow for capture of single key strokes via keyboard event listener(s), but playing about showed key-combos are _mostly_ caught quickly! Also it seems on Arch Linux (I use Arch BTW™) the `key` object sent through the `keyboard.listener` has a different _shape_, or perhaps the inconsistencies in capture behaviors got me jumping to wrong-thinking. Either way, these proposed changes _should_ preserve previously programmed `key.char` detection, while also allowing those stuck with Wayland to enjoy this tool.
1 parent d3ba0c8 commit 05f4fa6

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

manim_voiceover/services/recorder/utility.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ def __init__(self):
2121
self.key_pressed = None
2222

2323
def on_press(self, key):
24-
if not hasattr(key, "char"):
25-
return True
26-
27-
if key.char == "r":
24+
if hasattr(key, "r") or hasattr(key, "shift_r"):
2825
self.key_pressed = True
26+
elif hasattr(key, "char"):
27+
if key.char == "r" or key.char == "shift_r":
28+
self.key_pressed = True
2929

3030
return True
3131

3232
def on_release(self, key):
33-
if not hasattr(key, "char"):
34-
return True
35-
36-
if key.char == "r":
33+
if hasattr(key, "r") or hasattr(key, "shift_r"):
3734
self.key_pressed = False
35+
elif hasattr(key, "char"):
36+
if key.char == "r" or key.char == "shift_r":
37+
self.key_pressed = False
3838

3939
return True
4040

@@ -92,7 +92,7 @@ def _record(self, path):
9292
self.listener = MyListener()
9393
self.listener.start()
9494

95-
print("Press and hold the 'r' key to begin recording")
95+
print("Press and hold the 'r' (or Shift^R if on Wayland) key to begin recording")
9696
if self.first_call:
9797
print("Wait for 1 second, then start speaking.")
9898
print("Wait for at least 1 second after you finish speaking.")
@@ -103,7 +103,7 @@ def _record(self, path):
103103
)
104104
print("These instructions are only shown once.")
105105

106-
print("Release the 'r' key to end recording")
106+
print("Release the 'r' (or Shift^R if on Wayland) key to end recording")
107107
self.task = sched.scheduler(time.time, time.sleep)
108108
self.event = self.task.enter(
109109
self.callback_delay, 1, self._record_task, ([path])

0 commit comments

Comments
 (0)