jarvis
jarvis copied to clipboard
Focus application if open, instead of launching new instance
If there's already an instance open of an application it would be preferable to have that application receive focus instead of launching a new instance. That way Jarvis could be used to quickly to switch between applications in addition to launching them.
A key combination could force a launch of a new instance. Shift+Enter would be in keeping with the Windows default of launching new instances when shift-clicking an application on the taskbar and when using Win+Shift+
After googling a bit it looks like there's a few ways to activate a window of an external process:
ShowWindow/SetForegroundWindow
This requires importing user32.dll to use the Win32 API. According to this SO answer it might be necessary to call both functions to ensure the window is activated if it's been minimised.
SwitchToThisWindow
This also requires user32.dll, but seems to activate minimised windows too (according to this SO answer, but as a comment mentions, it's "not intended for general use. It may be altered or unavailable in subsequent versions of Windows" according to the MSDN docs
AppActivate
This function is located in the VisualBasic.dll and I'm not sure that would even work from C#.
@jonstodle I would prefer the ShowWindow/SetForegroundWindow
approach here. The API:s in question is commonly used and already available in Jarvis.Core.Interop.Win32
.
You want to take a stab at this?
Sure 🙂