dictation-toolbox / dragonfly

Speech recognition framework allowing powerful Python-based scripting and extension of Dragon NaturallySpeaking (DNS), Windows Speech Recognition (WSR), Kaldi and CMU Pocket Sphinx
GNU Lesser General Public License v3.0
383 stars 75 forks source link

Linux keyboard (pynput) #323

Closed codebold closed 3 years ago

codebold commented 3 years ago

Can anyone explain to me why libxdo or xdotool is used for Linux. xdotool always spawns a new process, which is pretty bad for action execution performance. I already started to code some evdev/uinput adapter, but found later that the pynput keyboard (currently used for mac only) works pretty good for Linux as well. So, are there any reasons why xdo is configured as Linux keyboard in the initialization, which i did not came across yet or did not thought about? Thanks!

If not, i would recommend to just use the pynput keyboard for Linux as well...

drmfinlay commented 3 years ago

Hello @codebold,

I can explain this. Xdotool is used on Linux/X11 because our original pynput keyboard implementation was simulating keys on X11 in such a way that global keyboard shortcuts weren't being triggered as expected. See issue #79. The keyboard shortcut in that issue was Ctrl+Alt+T for opening a terminal window.

I have just retried the old pynput keyboard implementation for X11 using pynput version 1.7.3 (latest). I note the same problem described in issue #79. I don't think this should be considered a bug, however.

My understanding of X11 synthetic/non-synthetic key events is limited, but it seems to me that both have legitimate use cases. For instance, when Emacs is the foreground window, I can either use the transpose-sexps function bound to C-M-t (using pynput) or my global shortcut for opening a terminal window (using xdotool), not both. Having said that, the current behaviour is the same as what happens when I use a real keyboard.

Let me know if you also see this difference in behaviour — it may be different on your system. I'm using Debian 10 with Xfce4. I'm happy to adjust Dragonfly to allow using either implementation, perhaps based on an environment variable.

xdotool always spawns a new process, which is pretty bad for action execution performance.

I have been using xdotool in this way for years with Aenea and Dragonfly. I haven't noticed issues with action execution performance due to this. Again, this may be different on your system.

codebold commented 3 years ago

First of all, thanks for the clarification. I did not run into this problem before, but i also did not finish setting everything up. Now i can confirm issue #79, as double modifiers (or at least 'ca-*') are not executed correctly.

For me, it makes a huge performance difference. I noticed from the debug console, that the recognition finishes early, whereas the key strokes are lagging. Maybe this is specific to my system. I'm running Ubuntu 18.04 with Gnome. So for me a mixed setup, where I run double modifiers with xdo, would probably be best, if i don't get this issue fixed otherwise. For now, I would suggest that I test this behavior further. When I gain new insights I can reopen this issue.