robotgo
robotgo copied to clipboard
[Feature Request] Send keys to minimized or inactive windows
- Robotgo version (or commit ref): 0.48.0
- Go version: go 1.10
- Gcc version: 7.3.0
- Operating system and bit: Windows 10 64bit / Linux manjaro 4.14.27 64bit
- Can you reproduce the bug at Examples:
- [ ] Yes (provide example code)
- [ ] No
- [x] Not relevant
Description
Is there a workflow available for sending keystrokes to background or inactive windows? Keystrokes sent with KeyTap() or TypeString() trigger the key events fine, and SetActive() can work to bring a window to the front to receive keystrokes, but I was wondering is there any way to send keys to an inactive or minimized window.
There seem to be some ways to do this with C# on Windows per this SO question's solutions. I'm not sure what complexity is involved with other OSes or with Golang though.
Is sending keys to minimized or inactive windows something that could ever be supported by Robotgo? Is there already a way that I missed?
Currently this function is not supported.
Thanks for confirming! If it is possible, it would be nice to see this feature built into robotgo someday. :)
I agree. This feature would be nice to have.
I actually came here looking for this. Anyone mind if I try implementing this or know if any work has been done yet? I'm thinking adding a func KeyToggleWindow(pid int32, args ...string) string (and related functions just with window at the end) that would send keys to the window with the given pid
For windows we'd use PostMessageA instead of SendInput https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-postmessagea or maybe PostThreadMessage to get info needed to wait and see if the message succeeded
Looks like cocoa can use CGEventPostToPSN instead of CGEventPost https://stackoverflow.com/questions/21878987/mac-send-key-event-to-background-window
@Noofbiz Thanks for your suggest.
Hmm it looks like for macOS you need accessibility permissions to send events to background apps. Just using CEEventPostToPID isn't enough. I'll see if I can get it working by building the app with the right permissions in XCode. It doesn't work by just running 'go run' in the terminal. It still sends the events only to the active window.
The problem I'm having with Mojave appears to be an issue with the new app sandboxing seen here https://stackoverflow.com/questions/51299066/macos-mojave-automator-not-authorized-to-send-apple-events-to-system-event. Not sure how to work around it at the moment
Very strongly concerned about this feature!!!
This would be awesome! I'm trying to write something to help multi boxing in World of Warcraft ( which is fine by their ToS and a practice many people do ) but need to be able to send keystrokes to non-active windows to get it working properly
And capturing screenshot of background window, looking forward to it :)
Hmm it looks like for macOS you need accessibility permissions to send events to background apps. Just using CEEventPostToPID isn't enough. I'll see if I can get it working by building the app with the right permissions in XCode. It doesn't work by just running 'go run' in the terminal. It still sends the events only to the active window.
FYI, I know this is an old post, but for me, on BigSur the CGEventPostToPid worked! (Just need enough delay or it won't get detected properly.) (I have added a PR to a different keyboard lib with that: https://github.com/micmonay/keybd_event/pull/37/files I used it to control OBS in the background.)
@Gerifield Thx, I will think about it.
Added it in the mac os, are there have PR in other platform?
I'm a Windows user and I'm looking forward to this feature
I'm a Windows user and I'm looking forward to this feature