不在焦点时在WPF C#应用程序中捕获按键 [英] Capture Keypress in WPF C# Application when not in focus

查看:67
本文介绍了不在焦点时在WPF C#应用程序中捕获按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使应用程序最小化或根本没有聚焦,我也想捕获PrintScreen按钮.我已经看到了一些片段,但是这些片段在WPF中均无效,仅在Winforms中有效.任何人都可以给出一些代码开始吗?

I want to capture the PrintScreen button even if the application is minimised or not on focus at all. I've seen some snippets but none of these worked in WPF, only in Winforms. Anyone can give some code to start?

推荐答案

有关如何在WPF应用程序中实现全局热键的示例,请参考以下博客文章.

Please refer to the following blog post for an example of how you could implement global hot keys in a WPF application.

在WPF中实现全局热键: 全局或系统范围内的热键是与特定窗口相关联的键或键组合,只要用户从系统中的任何位置按此键或组合键,它将接收消息.

A global, or system-wide, hot key is a key or a combination of keys that is associated with a particular window, which will receive messages whenever the user presses this key or key combination from anywhere in the system.

确实没有.NET API:可以为您的应用程序注册热键,但是有一个本机的RegisterHotKey方法,您可以使用P/Invoke从托管代码中调用该方法.请参考链接以获取更多信息.

There are indeed no .NET API:s to register hot keys for your application but there is a native RegisterHotKey method that you can call from managed code using P/Invoke. Please refer to the link for more information.

这篇关于不在焦点时在WPF C#应用程序中捕获按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆