Click here to Skip to main content
15,895,740 members
Articles / Mobile Apps

Using keyboard hooks in WinCE

Rate me:
Please Sign up or sign in to vote.
4.57/5 (14 votes)
1 Nov 2005CPOL1 min read 163.8K   1.3K   39  
The article shows how to use keyboard hooks in WinCE.
#ifndef _WINCE_KB_HOOK_H
#define _WINCE_KB_HOOK_H

//used for passing to SetWindowsHookEx funtion to set a Low level (LL) keyboard hook
#define WH_KEYBOARD_LL   		20

// Define the function types used by hooks
typedef LRESULT	(CALLBACK* HOOKPROC)(int code, WPARAM wParam, LPARAM lParam);
typedef HHOOK 		(WINAPI *_SetWindowsHookExW)(int, HOOKPROC, HINSTANCE, DWORD);
typedef LRESULT	(WINAPI *_CallNextHookEx)(HHOOK, int, WPARAM, LPARAM);
typedef LRESULT	(WINAPI *_UnhookWindowsHookEx)(HHOOK);


// For the low level keyboard hook, your keyboards procedures is passed a pointer to KBDLLHOOKSTRUCT instance
typedef struct {
    DWORD vkCode;
    DWORD scanCode;
    DWORD flags;
    DWORD time;
    ULONG_PTR dwExtraInfo;
} KBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT;


// Win32 Hook APIs 
static _SetWindowsHookExW 		SetWindowsHookEx;
static _UnhookWindowsHookEx	UnhookWindowsHookEx;
static _CallNextHookEx  		CallNextHookEx;	


/** 
*	Function Name:ActivateKBHook
*	
*	Function Desc:Initializes the proc. adress of various hook related APIs.
*				  Loads the keyboard hook.
*
*	Parameters:
*				 HINSTANCE hInstance : handle to the application to be hooked
*				 HOOKPROC LLKeyboardHookCallbackFunction : procedure where the control will come to after any KB event.
*	Returns:	
*				 true if we get all the proc addresses of hook related APIs and load the hook succesfully
*				 false if any of the above fails
*
*	Author:		 Prathamesh Kulkarni
**/
WINCEKBHOOK_API BOOL ActivateKBHook(HINSTANCE hInstance, HOOKPROC LLKeyboardHookCallbackFunction);

/** 
*	Function Name:DeactivateKBHook
*	
*	Function Desc:Uninstall the KB hook
*
*	Parameters:
*				 none
*	Returns:	
*				 true if we exit gracefully
*
*	Author:		 Prathamesh Kulkarni
**/
WINCEKBHOOK_API BOOL DeactivateKBHook();



#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions