2

I am writing a program to automate some work for me.

I have another program (OBS Studio) installed, which I use to capture video. OBS Studio is minimized to the system tray and listens to my configured hotkey CTRL + 1.

When I press CTRL + 1 anywhere, the software starts recording. It does not matter which application is in the foreground.

I am trying to do the same thing from my application, send a "global" hotkey. I have spend hours trying to achieve this, but without any result. SendKeys only works for the current open window (which does not exist), no results with PostMessage either and I tried the wrapper "InputSimulator"

So, to summarize:

  • Is it possible to send a hotkey/keystroke globally (for every application?)
  • If not, how would I send a hotkey to a program that is running in the background, without a window? I don't want to bring the app to the foreground.

Hopefully someone with a deeper understanding of these concepts can guide me...

I've found similar questions, but they remain unanswered:

Send global keystroke / fake a global hotkey from a Winforms application

Sources I studied (among others):

https://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys(v=vs.110).aspx https://dailyoverdose.wordpress.com/2009/10/28/postmessage-and-sendmessage/ https://ourcodeworld.com/articles/read/520/simulating-keypress-in-the-right-way-using-inputsimulator-with-csharp-in-winforms

Gerhard Schreurs
  • 663
  • 1
  • 8
  • 19
  • Get a list of active processes, iterate through it and SendKeys to each one. – 3Dave Aug 13 '18 at 21:39
  • I created a wpf app that would when running would add an icon to the tray. Then listen for all specific hotkeys ie alt f10 - f12 was mine. The user would select text in any app ie email, chat. Then hit the hotkey and would perform searches based on selected text. – Ryan Schlueter Aug 13 '18 at 21:45
  • Are you sure you don't want to hook the key event? I think that's what your OBS Studio is probably doing. See [SetWindowsHookEx function](https://msdn.microsoft.com/en-us/library/windows/desktop/ms644990(v=vs.85).aspx). – jwdonahue Aug 13 '18 at 21:57
  • Whats wrong with the existing answers? https://stackoverflow.com/questions/2450373/set-global-hotkeys-using-c-sharp – Jeremy Thompson Aug 13 '18 at 23:06

0 Answers0