SetWindowsHookEx to hook keyboard messages

How can I catch keystrokes on Pocket pc 2002 by calling the SetWindowsHookEx function?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

not sure on a Pocket PC, but on regular old windows this is an example:
DarioDeNicolaAuthor Commented:
i tried to load Hook functions from coredll.dll, this is the code:

typedef long (__cdecl *hookprocedure)(int,unsigned int,long);
typedef HHOOK  (__cdecl *sethook)(int,hookprocedure,HINSTANCE,DWORD);
typedef LRESULT  (__cdecl *nexthook)(HHOOK,int,WPARAM,LPARAM);

HHOOK hook;
nexthook nexthookfunction;

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
                           LPWSTR lpCmdLine,int nCmdShow)
      HINSTANCE library;      
      sethook sethookfunction;

      if((sethookfunction=(sethook) GetProcAddress(library,L"SetWindowsHookEx"))==NULL)

      if((nexthookfunction=(nexthook) GetProcAddress(library,L"CallNextHookEx"))==NULL)

      if((hook=sethookfunction(20,KeyLogProc,hInstance,0))== NULL)

but the call to GetProcAddress return a NULL pointer;
is there something wrong in the code?

thank u
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

After doing some poking around, it seems that there are no hooks supported in Windows CE (according to what I've seen).

about the only thing you can do is get keys pressed in your own application:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DarioDeNicolaAuthor Commented:
i've just tried to use GetAsyncKeyState first but it doesn't work:

i've created a loop to test the keystrokes with GetAsyncKeyState but, for example, if i press a 'a', during the loop the call GetAsyncKeyState on the character 'a' returns non-zero for 2-3-4 times depending how many times the system calls the function while the 'a' is down, do u understand?
so...i'm in troubles and if i don't resolve the question i can't terminate my universitary studies!! :-(
if u have a solution you will save me!!

I'm not sure I can help you with that..  

I could suggest reading the documentation on the function:

and maybe

this function only tells you the state of a particular key.  You have to ask the state of the 'a' key for example..

Return Values
If the function succeeds, the return value specifies whether the key was pressed since the last call to GetAsyncKeyState, and whether the key is currently up or down. If the most significant bit is set, the key is down. The least significant bit is not valid in Windows CE, and should be ignored. GetAsyncKeyState returns the current key state even if a window in another thread or process currently has the keyboard focus.
DarioDeNicolaAuthor Commented:
oh, i've already read about the GetAsyncKeyState, the problem is that the least significant bit is ignored in windows ce,according to the msdn documentation....
is there a low-level method to catch interrupts generated by pressing keys?

thank u
Something I found (probably no longer works) at

10.9 SetWindowsHookEx really does work, sort of.

If you believe the Microsoft documentation, SetWindowsHookEx does not work under Windows CE. However, if you have read this FAQ you know that SetWindowsHookEx can be found in coredll (2.11 PSPC and HPC Pro versions only). The question is, what does it do, and is it a full implementation.

I have been wanting to write an ATL control that passes messages (like WM_HIBERNATE) to VBCE. One way to do this is to create an ATL control, implement a connection point, and install a windows hook that monitors the message queue, and whenever a relevant message appears, fires an event off to VB. Unfortunately, every combination of

gHook = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC) MyWndProc, gInstance, 0);

returned an error 87 (incorrect parameter). Further searching through the PB header files reveals only three hook-related defines:

#define WH_KEYBOARD_LL 20

So I stopped using WH_CALLWNDPROC and tried WH_KEYBOARD_LL, and found that it worked quite well. I actually implemented a hook callback that watched for VK_OFF, and when detected, waited 2 seconds before returning. Whenever I pressed the power button the device would indeed wait before turning off. I also attempted to abort the power off by returning a non-zero number from the hook callback. While this does prevent the power button from powering off the device, it also causes the device to crash. Besides, VK_OFF is only generated when the off button is pressed, and not when a device time-out occurs, so the code was of marginal use. However, if you need to trap other low-level keyboard commands (ctrl-esc, etc) SetWindowsHookEx might be for you.

While I imagine journal record and playback are implemented as well, I have not tried them.

It's starting to sound like an extremely difficult task for CE..  I've checked some newsgoups:

look at the comments from these folks:

this one sounds like what you said.. like the bit is ignored:

and this one:

It may benefit you to post this question to that particular newsgroup.

also could check this....

DarioDeNicolaAuthor Commented:
I've used GetAsyncKeyState and some test variables to detect pressed keys from an external keyboard and it works fine!!
but i've an another problem:how can I detect inputs coming from the SIP?
is there a way to realize a complete pocket pc keylogger that logs external keybord inputs and sip inputs?
please help me!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.