Skip to content

Commit

Permalink
Add support for dotool
Browse files Browse the repository at this point in the history
  • Loading branch information
johngebbie authored and ideasman42 committed Nov 3, 2022
1 parent 662f7f3 commit 02af2f8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
1 change: 1 addition & 0 deletions changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Changelog
#########

- 2022/11/03: Add ``dotool`` support with ``--simpulate-input-tool=DOTOOL``.
- 2022/06/05: Add packaging script for PIP/setup-tools to optionally install via PIP.
- 2022/05/16: Add ``ydotool`` support with ``--simpulate-input-tool=YDOTOOL``.
- 2022/04/18: Add ``--input`` option to specify audio recording command, added ``sox`` input.
Expand Down
33 changes: 25 additions & 8 deletions nerd-dictation
Original file line number Diff line number Diff line change
Expand Up @@ -1061,13 +1061,29 @@ def main_begin(
#
if output == "SIMULATE_INPUT":

def handle_fn(text: str, delete_prev_chars: int) -> None:
if delete_prev_chars:
# Backspace keycode. In ydotool we need to mark the key pressed with :1, then release it with :0
# The default delay between keypresses is long and key delay stands for one key state change,
# so 3 ms == 6 ms to press and release backspace once.
simulate_backspace_presses(delete_prev_chars, simulate_input_tool)
simulate_typing(text, simulate_input_tool)
if simulate_input_tool == "DOTOOL":
dotool = subprocess.Popen("dotool", stdin=subprocess.PIPE, text=True)
assert dotool.stdin is not None
dotool.stdin.write("keydelay 4\ntypedelay 12\n")
dotool.stdin.flush()

def handle_fn(text: str, delete_prev_chars: int) -> None:
assert dotool.stdin is not None
if delete_prev_chars:
dotool.stdin.write("key" + " backspace" * delete_prev_chars + "\n")
dotool.stdin.flush()
dotool.stdin.write("type " + text + "\n")
dotool.stdin.flush()

else:

def handle_fn(text: str, delete_prev_chars: int) -> None:
if delete_prev_chars:
# Backspace keycode. In ydotool we need to mark the key pressed with :1, then release it with :0
# The default delay between keypresses is long and key delay stands for one key state change,
# so 3 ms == 6 ms to press and release backspace once.
simulate_backspace_presses(delete_prev_chars, simulate_input_tool)
simulate_typing(text, simulate_input_tool)

elif output == "STDOUT":

Expand Down Expand Up @@ -1344,12 +1360,13 @@ def argparse_create_begin(subparsers: argparse._SubParsersAction) -> None:
"--simulate-input-tool",
dest="simulate_input_tool",
default="XDOTOOL",
choices=("XDOTOOL", "YDOTOOL", "WTYPE"),
choices=("XDOTOOL", "DOTOOL", "YDOTOOL", "WTYPE"),
metavar="SIMULATE_INPUT_TOOL",
help=(
"Program used to simulate keystrokes (default).\n"
"\n"
"- ``XDOTOOL`` Compatible with the X server only (default).\n"
"- ``DOTOOL`` Compatible with all Linux distributions and Wayland.\n"
"- ``YDOTOOL`` Compatible with all Linux distributions and Wayland but requires some setup.\n"
"- ``WTYPE`` Compatible with Wayland.\n"
" For help on setting up ydotool, see ``readme-ydotool.rst`` in the nerd-dictation repository.\n"
Expand Down
6 changes: 4 additions & 2 deletions readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ Dependencies
- ``parec`` command for recording from pulse-audio (default) or
``sox`` command as alternative.
See the guide: `Using sox with nerd-dictation <readme-sox.rst>`_.
- ``xdotool`` (default, X11 only) or
``ydotool`` command to simulate keyboard input (supports X11 & Wayland).
- ``xdotool`` command to simulate input in X11 (default) or
``dotool`` command to simulate input anywhere (X11/Wayland/TTYs) or
``ydotool`` similar to dotool but requires setup and a daemon to be running.
See the setup guide: `Using ydotool with nerd-dictation <readme-ydotool.rst>`_
or ``wtype`` an "xdotool for wayland"

Expand Down Expand Up @@ -243,6 +244,7 @@ options:
Program used to simulate keystrokes (default).

- ``XDOTOOL`` Compatible with the X server only (default).
- ``DOTOOL`` Compatible with all Linux distributions and Wayland.
- ``YDOTOOL`` Compatible with all Linux distributions and Wayland but requires some setup.
- ``WTYPE`` Compatible with Wayland.
For help on setting up ydotool, see ``readme-ydotool.rst`` in the nerd-dictation repository.
Expand Down

0 comments on commit 02af2f8

Please sign in to comment.