Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global HotKey in Universal Windows App

So I created an UWP App that can record several Audio Lines and save the recordings to MP3 files for in-game multi-line recording that I can later edit separately (game audio, microphone, game comms, voice comms) as NVidia ShadowPlay/Share does not support this yet. I achieve this multi-line setup with VAC.

I have a version of this tool written in regular Windows WPF C# and I have a system-wide HotKey Ctrl+Alt+R that starts/stops recording so when I'm in a full screen game, I can start/stop recording without exiting full screen mode (switching window focus).

Can a global (system wide, app window not in focus) HotKey that triggers some in-App event be achieved in a UWP App? I know the functionality is not supported for other platforms. But I only need it to run on Windows 10 Desktop and the HotKey support is mandatory. Or can I achieve my goal in any other way for UWP Apps?

GOAL: System wide key combination to trigger in UWP app event without switching Window focus and messing with full-screen games.

like image 232
CodeAngry Avatar asked Oct 29 '22 04:10

CodeAngry


1 Answers

at the moment it is not possible to solve this task thoroughly. You are facing two limitations of UWP and can be only partially solved:

  • Lifecycle: UWP apps go in suspended state when they are not focused. They just "block" to consume less resources (and battery). This is a great feature for mobile devices, but is bad news for you project. You can solve this by requesting "ExtendedExecutionSession" which will guarantee that your app never falls asleep when out of focus if "attached to wallpower".

  • Detect input without focus. It's clearly stated on MSDN that UWP doesn't support keyboard HOOKS (this refers to SetWindowsHookEx). They reinvented "GetAsyncKeyState", now it works only when the Windows is focused. Indeed you can find that under CoreWindow.GetAsyncKeyState(). If you only need to use F Keys as hotkeys you can still do something, like "press F2 when the app is minimzed to activate a function". Use Stefan Wick example. He solved part of the problem. Instead if you need to listen to lots of keys (or mouse events) there isn't a way. You can't right now.

Curiosity

UWP has restricted capabilities, one of which called "InputObservation". At the moment it is not documented and impossible to implement (unless you are a select Microsoft Partner), but it should allow apps to access system input (keyboard/mouse..) without any limitation and regardless its final destination. I think this feature is the key for system-wide inputs detection. I am not able to find a way to implement it.

Kind Regards

like image 161
RosDevil Avatar answered Nov 04 '22 23:11

RosDevil