如何控制Windows Mobile 手机键盘操作
最近在做Mobile上的应用的时候,想截取Windows Mobile的按下OK键的消息,并做一些自定义处理。
在网上看了很多文章,但是发现很少有谈到这个问题的。后来还是找到了点资料。所以拿出来和大家分享一下。
首先要在OnInitDialog注册热键,这样才能在WM_HOTKEY消息中得到响应。
- typedef BOOL(__stdcall *UnregisterFunc1Proc)(UINT,UINT);
- HINSTANCE hCoreDll;
- UnregisterFunc1Proc procUndergisterFunc;
- hCoreDll = LoadLibrary(_T( "coredll.dll "));
- ASSERT(hCoreDll);
- procUndergisterFunc = (UnregisterFunc1Proc)GetProcAddress(hCoreDll,_T( "UnregisterFunc1 "));
- BOOL bRes = RegisterHotKey(m_hWnd, VK_TACTION,NULL,VK_TACTION);
typedef BOOL(__stdcall *UnregisterFunc1Proc)(UINT,UINT);
HINSTANCE hCoreDll;
UnregisterFunc1Proc procUndergisterFunc;
hCoreDll = LoadLibrary(_T( "coredll.dll "));
ASSERT(hCoreDll);
procUndergisterFunc = (UnregisterFunc1Proc)GetProcAddress(hCoreDll,_T( "UnregisterFunc1 "));
BOOL bRes = RegisterHotKey(m_hWnd, VK_TACTION,NULL,VK_TACTION);
在Windows Mobile
Smartphone平台下,VK_TSOFT1,VK_TSOFT2等都被系统注册为热键,如果在自己的应用在需要响应这些按键事件,需要先从系统中注
销,然后注册后对WM_HOTKEY事件进行响应即可。但是注销系统热键的API函数并没有公开,需要使用一个coredll.dll中一个未公开API
函数.
注册消息映射:
- ON_MESSAGE(WM_HOTKEY,&CMyllecSMS2Dlg::OnHotKey)
-
- HRESULT CMyllecSMS2Dlg::OnHotKey(WPARAM wParam,LPARAM lParam)
- {
- int idHotKey = (int)wParam;
- UINT fuModifiers = (UINT)LOWORD(lParam);
- UINT uVirtKey = (UINT)HIWORD(lParam);
- static BOOL bPressed = FALSE;
- if (idHotKey == VK_TACTION)
- {
- HTREEITEM selectedItem = m_mainTree.GetSelectedItem();
- SelectedTreeNodeDoubleClick(selectedItem);
- }
- else
- {
-
- }
- return TRUE;
- }
ON_MESSAGE(WM_HOTKEY,&CMyllecSMS2Dlg::OnHotKey)
HRESULT CMyllecSMS2Dlg::OnHotKey(WPARAM wParam,LPARAM lParam)
{
int idHotKey = (int)wParam;
UINT fuModifiers = (UINT)LOWORD(lParam);
UINT uVirtKey = (UINT)HIWORD(lParam);
static BOOL bPressed = FALSE;
if (idHotKey == VK_TACTION)
{
HTREEITEM selectedItem = m_mainTree.GetSelectedItem();
SelectedTreeNodeDoubleClick(selectedItem);
}
else
{
}
return TRUE;
}
另外在解决该问题时看到一些朋友发帖问如何在自己的应用中响应一些系统热键如VK_LEFT,VK_RIGHT等的KEY_DOWN事件,增加自己的处理过程,该问题有两种解法
1。向上面那样注册成热键,然后根据按键状态模拟出按键按下事件
2。利用GPAI的GXOpenInput,将所有的按键事件纳入掌控中
大家可通过下面的视图查看,键对应的Key值
-
-
- sofkey1 softkey2 VK_TSOFT1, VK_TSOFT2
- ^ VK_TUP
- < + > VK_TLEFT, VK_TACTION, VK_TRIGHT
- v VK_TDOWN
- home back VK_THOME, VK_TBACK
- talk end VK_TTALK, VK_TEND
- 1 2 3 VK_T0..VK_T9
- 4 5 6 ...
- 7 8 9 ...
- * 0 # VK_TSTAR, VK_TPOUND
-
- VK_TRECORD
- VK_TPOWER, VK_TVOLUMEUP, VK_TVOLUMEDOWN
- VK_TFLIP
阅读(847) | 评论(0) | 转发(0) |