惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
N
Netflix TechBlog - Medium
腾讯CDC
C
Check Point Blog
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
S
SegmentFault 最新的问题
F
Fortinet All Blogs
美团技术团队
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
F
Full Disclosure
Recorded Future
Recorded Future
D
DataBreaches.Net
博客园 - 【当耐特】
Martin Fowler
Martin Fowler
J
Java Code Geeks
I
InfoQ
Y
Y Combinator Blog
A
About on SuperTechFans
AI
AI
爱范儿
爱范儿
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Forbes - Security
Forbes - Security
W
WeLiveSecurity
M
MIT News - Artificial intelligence
雷峰网
雷峰网
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
Schneier on Security
Schneier on Security
The GitHub Blog
The GitHub Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Docker
Recent Commits to openclaw:main
Recent Commits to openclaw:main
量子位
V2EX - 技术
V2EX - 技术
Project Zero
Project Zero

博客园 - 我是程序员

Kubernetes集群安全概述 EventStore .NET API Client在使用线程池线程同步写入Event导致EventStore连接中断的问题研究 Silverlight下实现Windows8风格的进度条 如何确保Silverlight按照区域设定自动加载对应区域的资源 查看进程的启动参数 (转) 如何在Access2007中打开加密的Access2003数据库 业务流程不是需求(ZT) 如何取消ActiveReport的打印任务 开源license总结(转) 如何将文本文件读入到DataSet中 利用Eclipse调试JSP XML文件的DOCTYPE定义(转) - 我是程序员 - 博客园 如何定制Acegi验证框架的验证错误信息 别让Hibernate偷走了您的身份(转) Firefox下强制页面缓存失效的设置方法 - 我是程序员 - 博客园 有关Struts标签<html:cancel>使用的一点提示 - 我是程序员 - 博客园 Struts Commons-validator的validation.xml验证文件的配置指南(转) - 我是程序员 - 博客园 大型Web2.0站点构建技术初探(转) 面向对象分析设计的六十一条经验原则(转贴)
在WPF中如何注册热键
我是程序员 · 2009-07-09 · via 博客园 - 我是程序员

不说废话,直接看代码吧,其关键就是 System.Windows.Interop.HwndSource类。

第一步:注册热键,需要使用API函数,具体的参照网上的其它文章。唯一需要注意的是需要使用KeyInterop.VirtualKeyFromKey函数将

WPF的Key枚举转化为API函数可以使用的VirtualKeyCode :

注册热键API函数定义

 第二步:注册热键处理函数,主要的难点就在这里,在.NET的WinForm程序中一般使用重写Form的WinProc方法或者注册IMessageFilter来实现的,

但是在WPF中以上两种方式都无法获得热键消息的处理机会,除非是在WPF程序中隐藏一个常规的Form(最开始就是这么弄得,后来觉得实在是太丑陋了)

注册热键处理函数

 以上代码在Windows2008下测试通过。