Is it possible for a Racket program to send keystrokes to the current app in a desktop environment?
Wondering if I can substitute a Racket program/DSL for for Autohotkey, which is atrocious.
Is it possible for a Racket program to send keystrokes to the current app in a desktop environment?
Wondering if I can substitute a Racket program/DSL for for Autohotkey, which is atrocious.
I realize I may be resurrecting something that has no great answer but I've run into the exact same use case as @joeld. That is I want to send keystrokes to a windows app (not one I've created with Racket GUI) and Autohotkey isn't well suited to that purpose.
If I could somehow figure out a way to get the HWND of the app I want to send the keystrokes to is there a way (short of FFI to Windows OS) to send keystrokes?
It feels as if it's so close but nothing I'm finding in the docs is giving me an answer and my own trial fumbling isn't working as I would have hoped either. I mean subprocess will hand back a pid for me but that doesn't do the trick.
Any ideas or suggestions? Even though I would vastly prefer something in Racket I'm happy with anything anyone can suggest for this one.
Is there a reason you don't want to use the FFI?
I don't know how to do this on Windows with or without Racket, but I'd expect it would mean calling some kind of system API, and the FFI is the best way to do that in general.
No good reason not to use the FFI. I wanted to avoid it to try to keep it platform agnostic but I think that's just not an option in this case.
Being cross-platform is great! Making a feature like this work across platforms typically means analyzing what the platform-specific features are available on all platforms of interest (e.g. uinput
from the Linux kernel) and designing a cross-platform interface to all of the platform-specific backend implementations.
I am reminded by the following code:
It contains code that uses the FFI to take screenshots on macOS.
The part that finds the displays and active windows might be usable in a "send key event to window" program.