Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 919
  • Last Modified:

SetWindowsHookEx to hook keyboard messages

How can I catch keystrokes on Pocket pc 2002 by calling the SetWindowsHookEx function?
0
DarioDeNicola
Asked:
DarioDeNicola
  • 5
  • 4
1 Solution
 
jrocnuckCommented:
not sure on a Pocket PC, but on regular old windows this is an example:

http://www.shellfront.org/modules/source/mrjukes/LiteStroker/LiteStroker.c
0
 
jrocnuckCommented:
0
 
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((library=LoadLibrary(L"coredll.dll"))==NULL)
            PostQuitMessage(1);

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

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

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


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

thank u
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
jrocnuckCommented:
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:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceui/htm/_wcesdk_Receiving_Keyboard_Input.asp?frame=true

0
 
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!!

thanks  
0
 
jrocnuckCommented:
I'm not sure I can help you with that..  

I could suggest reading the documentation on the function:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcesdkr/html/_wcesdk_Win32_GetAsyncKeyState.asp?frame=true

and maybe

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceui40/html/cerefcheckingotherkeys.asp

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.
0
 
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
0
 
jrocnuckCommented:
Something I found (probably no longer works) at  http://www.cegadgets.com/wincedevfaq.htm#5.17%20How%20can%20I%20reprogram%20the%20buttons%20on%20the%20device?%20Can%20I%20use%20hardware%20buttons%20to%20initiate%20application%20functionality?

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_JOURNALRECORD 0
#define WH_JOURNALPLAYBACK 1
#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:

http://groups.google.com/groups?q=GetAsyncKeyState+windows+ce&hl=en&lr=&ie=UTF-8&selm=7on3rl%24oqs%241%40nnrp1.deja.com&rnum=3

this one sounds like what you said.. like the bit is ignored:
http://groups.google.com/groups?q=GetAsyncKeyState+windows+ce&hl=en&lr=&ie=UTF-8&selm=8h43l4%24spv%241%40nnrp1.deja.com&rnum=5

and this one:
http://search.communities.microsoft.com/newsgroups/previewFrame.asp?ICP=GSS3&sLCID=US&sgroupURL=microsoft.public.windowsce.platbuilder&sMessageID=%253COWujAj6mDHA.3504@TK2MSFTNGP11.phx.gbl%253E


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


also could check this.... http://www.pocketpcdn.com/sections/input.html

0
 
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!!
thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now