Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send virtual key events to a specifc process/PID ? #118

Open
alphastrata opened this issue Apr 12, 2022 · 5 comments
Open

Send virtual key events to a specifc process/PID ? #118

alphastrata opened this issue Apr 12, 2022 · 5 comments
Labels

Comments

@alphastrata
Copy link

Describe your Question
Want to send key events to a specific process/PID/Window.

Describe your Goal
Use reddit on one monitor while my bot sends virtual key-presses to another window of my choosing.

Environment (please complete the following information):

  • Windows 10
  • Rust Version = latest.
  • Library Version = latest.
@pentamassiv
Copy link
Collaborator

I do not know how that would be possible. At least for Linux Wayland I don't think it would work because none of the protocols seem to allow choosing the window. If anyone knows how this could be achieved, please let me know.

@pythoneer
Copy link
Member

It might be possible under Windows (not sure, my memory of the windows api fades over the years :P) and i am also quite sure its not possible under Linux. This also opens the question how do we proceed with things that are not possible on all supported platforms.

@pentamassiv
Copy link
Collaborator

Under Linux X11 it seems to be possible. At least the xdotools man page says:

KEYBOARD COMMANDS
       key [options] keystroke [keystroke ...]
           Options:

           --window window
               Send keystrokes to a specific window id. You can use "WINDOW STACK"
               references like "%1" and "%@" here. If there is a window stack, then "%1"
               is the default, otherwise the current window is used.

And it includes a few examples:

Examples:
            # Activate google-chrome when you move the mouse to the bottom-left corner:
            xdotool behave_screen_edge bottom-left \
              search --class google-chrome windowactivate

            # Go to the next workspace (right). Known to work in GNOME (metacity and compiz)
            xdotool behave_screen_edge --delay 500 bottom-right key XF86Forward

            # Activate firefox and do a web search in a new tab for text in your clipboard
            xdotool behave_screen_edge --delay 1000 top-left \
                search --classname Navigator \

@pentamassiv
Copy link
Collaborator

I am not familiar with Windows, but I found this:
https://github.com/eHonnef/afk-clicker/blob/master/windows/Main.py
It looks like it is possible with Windows as well.

@pentamassiv
Copy link
Collaborator

It also looks like it is possible with macOS. There is post_to_pid, so we should be able to send the events to a specific process/window.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants