![]() |
|
QA: How can I handle hardware keys in my application?
By Vassili Philippov, September 11, 2001.
QuestionBy default pressing hardware keys launches other applications (such as Contacts, Calendar, etc). I need to handle hardware keys in my program. How can I do it? AnswerYou should register your window to handle hardware keys. Documentation says that you have to call RegisterHotKey function for that. But it is not enough. You should also call undocumented function UnregisterFunc1 defined in coredll.dll. After that you could handle pressing hardware keys by handling WM_KEYUP event. Here is a code that loads UnregisterFunc1 function from coredll.dll library: CSTUtilSTUtil library encapsulates working with this undocumented function. Just use RegisterHotKey method of CSTUtil class that works like standard RegisterHotKey WinAPI function but also calls necessary undocumented function. Sample applicationYou could download sample application (52 Kb) that handles all hardware keys and shows a message box when a key is pressed. Sample codeUsing STUtil libraryDownload STUtil library. Here is a sample code that registers a window to handle all hardware buttons: Without STUtil libraryHere is a sample code that registers a window to handle all hardware buttons without using STUtil library: Related resources:
DiscussDiscuss this article. Here you can write your comments and read comments of other developers. |
|||||||||||||||||||||