micmonay / keybd_event

For simulate key press in Linux, Windows and Mac in golang
MIT License
380 stars 57 forks source link

Make it possible to target background applications in OSX #37

Closed Gerifield closed 1 year ago

Gerifield commented 2 years ago

Hi,

first of all, I know it's not a cross-platform solution, I'll try to make adjustments on other platforms (if they are possible, I'm open to any help/suggestion on this topic.).

My issue was that the keyboard events were sent only to the application/window in focus on OSX, but I wanted to control an OBS instance that was running in the background. I cam across a possible solution via the CGEventPostToPid framework call.

For me this helped a lot, maybe could be useful for others too. (I'm not that happy to introduce a new constructor, but that was the easiest a fastest for me.)

micmonay commented 1 year ago

Sorry for many time wait... Thanks for your pull request You can create your own library for this solution, because I'm not adding any new features.