简体   繁体   English

通用 Windows 应用程序中的全局热键

[英]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.所以我创建了一个 UWP 应用程序,它可以录制多条音频线并将录音保存到 MP3 文件中,以便在游戏中进行多线录制,稍后我可以将其单独编辑(游戏音频、麦克风、游戏通信、语音通信)作为 NVidia ShadowPlay/Share还不支持这个。 I achieve this multi-line setup with VAC.我用 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) .我有一个用普通 Windows WPF C# 编写的这个工具的版本,我有一个系统范围的热键Ctrl+Alt+R开始/停止录制,所以当我在全屏游戏中时,我可以开始/停止录制而不退出全屏模式(切换窗口焦点)

Can a global (system wide, app window not in focus) HotKey that triggers some in-App event be achieved in a UWP App?是否可以在 UWP 应用程序中实现触发某些应用程序内事件的全局(系统范围,应用程序窗口未聚焦)热键? 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.但我只需要它在 Windows 10 桌面上运行,并且热键支持是强制性的。 Or can I achieve my goal in any other way for UWP Apps?或者我可以通过任何其他方式为 UWP 应用实现我的目标吗?

GOAL : System wide key combination to trigger in UWP app event without switching Window focus and messing with full-screen games.目标:系统范围内的组合键可在 UWP 应用事件中触发,而无需切换窗口焦点并干扰全屏游戏。

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:您正面临 UWP 的两个限制,只能部分解决:

  • Lifecycle: UWP apps go in suspended state when they are not focused.生命周期:UWP 应用在未获得焦点时进入暂停状态。 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" .您可以通过请求 "ExtendedExecutionSession" 来解决这个问题,这将保证您的应用程序在“附加到 wallpower”时不会在失焦时进入睡眠状态。

  • Detect input without focus.在没有焦点的情况下检测输入。 It's clearly stated on MSDN that UWP doesn't support keyboard HOOKS (this refers to SetWindowsHookEx). MSDN上明确说明UWP不支持键盘HOOKS(这里指的是SetWindowsHookEx)。 They reinvented "GetAsyncKeyState", now it works only when the Windows is focused.他们重新发明了“GetAsyncKeyState”,现在它只有在 Windows 聚焦时才有效 Indeed you can find that under CoreWindow.GetAsyncKeyState().事实上,您可以在 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".如果你只需要使用 F 键作为热键,你仍然可以做一些事情,比如“当应用程序最小化时按 F2 激活功能”。 Use Stefan Wick example .使用 Stefan Wick 示例 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 " . UWP 具有受限的功能,其中之一称为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亲切的问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM