开发者

How to hook hotkeys in winforms or WPF from a .NET 2.0 assembly?

I have assembly that targets .NET 2.0 to be compatible with a broad range of applic开发者_C百科ations. When used with a desktop application (either winforms or WPF) I want to hook certain hotkeys and popup modeless dialog windows. The tricky bit is finding a solution that can be implemented under .NET 2.0 that is compatible with WPF.

For winforms I could use RegisterHotKey or implement IMessageFilter and hook WM_KEYDOWN in the PreFilterMessage method, but they don't work well with WPF.

For WPF, the InputBinding class is very nice, but this isn't available in .NET 2.0.

An ideal solution would:

  • Build in an assembly targeting .NET

  • Hook keystrokes for either WPF or Winforms

  • Provide application-wide, not system-wide scope


You could build a universal solution based on Windows API (System wide hook). Don Esposito has written a great article on that. Here's a link

http://msdn.microsoft.com/en-us/magazine/cc188966.aspx

You could write an application hook too if you don't want a system wide hook. That's actually easier to implement. Don covers that too I think.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜