Using keyboard hooks in WinCE
来源:互联网 发布:js border-color 编辑:程序博客网 时间:2024/05/22 01:47
http://www.codeproject.com/KB/mobile/wincekbhook.aspx
http://www.codeproject.com/KB/mobile/KeyboardhooksWinCE.aspx
- Download source files - 2.21 Kb
Introduction
The article shows how to use keyboard hooks in WinCE.
Background
I came across a problem where I had to remap certain special keys on my handheld for an existing dialog based application. The only solution I knew that would gracefully do this in WinCE was hooks. But MSDN states that hook APIs aren't supported in WinCE. But I found that they were present in coredll.lib. So, I thought of manually loading these APIs and using them. Initially, I did have some problems doing this, but a look into winuser.h in VC++, made the job a lot easier. Googling also helped me to some extent, but I don't remember the URLs now, my apologies to those whom I haven't given the credit.
Using the code
You just have to use two files winceKBhook.cpp and winceKBhook.h. The code has been commented thoroughly for easy understanding. You can use these files in either an EXE or a DLL.
The mechanism of using a hook would be to install it. This is done using the function ActivateKBHook()
in winceKBhook.cpp. This function loads the necessary hook APIs and installs the keyboard hook. It is necessary to pass the handle of the application to be hooked and a low level keyboard procedure, which has to be defined by the user. All the keyboard events come to this procedure. Your code can then manage these events the way you want. The example shown below just remaps the keys. After you are done with using the hook you can unload it using DeActivateKBHook()
.
//Install the KB hook by passing the //handle of the application to be hooked //and the address of the KB procedure //which will handle all the KB eventsif(!ActivateKBHook(hInstance, LLKeyboardHookCallbackFunction)){ MessageBox(GetActiveWindow(), TEXT("Couldn't intall hook...Terminating"), TEXT("Warning"), NULL); exit(1);}//LLKeyboardHookCallbackFunction is the funtion whose //address we passed to the system while installing the hook.//so all the KB events will bring the control to this procedure.//Here we want that when the user presse left or //right key it should be interpreted as an UP key//so now you can allow the user to configure the //key boards the way he/she wants itLRESULT CALLBACK LLKeyboardHookCallbackFunction( int nCode, WPARAM wParam, LPARAM lParam) { if(((((KBDLLHOOKSTRUCT*)lParam)->vkCode) == VK_LEFT) || ((((KBDLLHOOKSTRUCT*)lParam)->vkCode) == VK_RIGHT)) { //Generate the keyboard press event of the mapped key keybd_event(VK_UP, 0, 0, 0); //release the mapped key keybd_event(VK_UP, 0, KEYEVENTF_KEYUP, 0); } //let default processing take place return CallNextHookEx(g_hInstalledLLKBDhook, nCode, wParam, lParam);}//we are done with the hook. now uninstall it.DeactivateKBHook();
- Using keyboard hooks in WinCE
- Processing Global Mouse and Keyboard Hooks in C#
- Processing Global Mouse and Keyboard Hooks in C#
- Processing Global Mouse and Keyboard Hooks in C#
- Using Keyboard Interface Control in Windows
- Using Netfilter hooks
- msysgit hooks using lua
- Writing Loadable Kernel Modules using netfilter hooks (in-depth HOWTO) – Part 1
- Writing Loadable Kernel Modules using netfilter hooks (in-depth HOWTO) – Part 1
- Writing Loadable Kernel Modules using netfilter hooks (in-depth HOWTO) – Part 1
- Using Keyboard Input
- Global System Hooks in .NET
- Global System Hooks in .NET
- Global System Hooks in .NET
- PasswordSpy - Retrieving lost passwords using Windows hooks
- Read and Write to a Keyboard device in Linux using C++
- How to make a custom keyboard in iOS 8 using Swift
- Hooks
- 兵法教程--经理人技能二:调配资源
- 3种方式遍历Repeater中的CheckBox全选
- 写博客需要坚持
- wince中的hook(钩子)用法
- firefox 中 innerText,innerHTML,textContent
- Using keyboard hooks in WinCE
- WINCE勾子使用方法(转)
- SQL中如何用一个表更新另一个表
- [摘]什么是游标(cursor)?
- 广州下调失业保险缴费比例90% 养老保险个人账户缴费基数有变
- iptables 中配置vsftp的访问
- C3P0连接池异常处理
- WINCE的钩子
- Java里面的路径问题,CLASSPATH和SOURCEPATH