C# 視窗程式範例--攔截系統按鍵


I've built a winforms application which checks for CTR+ALT+S and CTRL+ALT+E keypresses, using by overriding the ProcessCmdKey method. This works great, but if the screensaver goes on and then goes off the form doesn't have focus and the keypresses aren't intercepted. How can I receive these even if the form does not have focus?

2 Answers

1. Alexander Werner has a "System Hotkey Component" project over at Code Project that wraps the RegisterHotkey() API into a user control that's really easy to implement

2. I'm aware of two methods:

  1. RegisterHotKey() - You can use the RegisterHotKey() function to define a system-wide hot key. If the user presses the hotkey, Windows sends a WM_HOTKEY message.
  2. Win32 Hooks - This is an old API originally designed to support computer-based training (CBT) applications, but I believe that Windows still supports it. The API allows you to intercept and possibly modify messages, mouse actions, and keystrokes for any window.

These are Win32 APIs, not .NET APIs, but .NET uses the same underlying components of Windows so the methods ought to work with .NET.

http://stackoverflow.com/questions/553870/intercep...

陳鍾誠 (2011年12月13日),(網頁標題) 攔截系統按鍵,(網站標題) 免費電子書:C# 程式設計,2011年12月13日,取自 http://cs0.wikidot.com/interceptkey ,網頁修改第 0 版。

arrow
arrow

    Johnson峰 發表在 痞客邦 留言(0) 人氣()