Thread: hcbt_keyskipped problems

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    100

    hcbt_keyskipped problems

    Hey all,

    Im having problems with a dll im coding. For some reason the following code doesnt work correctly:

    Code:
    LRESULT CALLBACK HookProcedure (int nCode, WPARAM wParam, LPARAM lParam )
    {                
        if (nCode == HCBT_KEYSKIPPED)
        {        
    system("echo hcbt_keyskipped >> test.txt");
                      ::PostMessage(mywindow, MSG_WM_KEYDOWN, wParam, lParam);
            
        }
        else if (nCode == HCBT_SETFOCUS)
        {
    system("echo hcbt_setfocus >> test.txt");
            ::PostMessage(mywindow, MSG_WM_SETFOCUS, wParam, lParam);
    }
    return CallNextHookEx( 0, nCode, wParam, lParam);
    }
    As you can see both of the IF statements use the system call to output a message to test.txt saying when the contents of the IF statements are being executed. This works correctly for setfocus but not keyskipped and i cant understand why because essentially they are the same code.

    Note. This isnt a problem with the message MSG_WM_KEYDOWN or the mywindow variable. It also isnt a problem with my includes (i think!).

    The way the setfocus works is when i run the dll whenever i change window it writes to the test.txt file showing it has registered the change of window focus, however when i press a key it should write to a the test.txt file showing it has registered the keypressing but it doesnt which implies IF(nCode == HCBT_KEYSKIPPED) is never true, but it should be. Im really stumped on this so any help would be appreciated.

    Thanks

    Mike

    NOTE.

    This might be important. The above code works fine when ran on some computers but not others, which seems strange as they are all running winxp pro. This suggests that the coding is fine but the OS is set up differently on some computers allowing it to work but not on others... If anyone knows why this is so then please say. Thanks

  2. #2
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    HCBT_KEYSKIPPED (Third link down when google'ing "HCBT_KEYSKIPPED")
    "Windows calls the WH_CBT hook with this hook code when a keyboard event is removed from the system queue and the keyboard hook is set. Windows will call a systemwide hook when a keyboard event is removed from any input queue and either a systemwide keyboard hook or a thread-specific hook for the current thread is installed. This hook code is not generated unless a filter function is attached to the WH_KEYBOARD hook. Despite its name, HCBT_KEYSKIPPED is called not only for skipped keyboard events but also whenever a keyboard event is removed from the system queue. Its main use is to install a WH_JOURNALPLAYBACK hook in response to a keyboard event. (See the "WM_QUEUESYNC" section below for more information.)"

    [edit]
    Once upon a time, I wrote a hook doing what it appears you intend to accomplish, logging all keystrokes and the current application in which said keys are being stroked. I succeeded using two hooks: a WH_CBT for capturing various process information and WH_KEYBOARD for detecting key presses. Good luck.
    [/edit]
    Last edited by LuckY; 12-22-2005 at 04:19 PM.

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    100
    thankyou for the information :-)

    i must admit im a bit stumped from where to go from here. I guess i need to generate a filter funcation but i dont know what its purpose will be. I dont want you to supply the code as I want to code it myself and as I know my lecturer browses this board I may get into trouble for plagurism lol.

    So if you can explain what the filter function will do and how to use it with the WH_KEYBOARD code then it would be very much appreciated.

    Thanks a lot :-)

    Mike

  4. #4
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    You probably replied before reading the edit appended to my previous message, but try using two hooks as I described. It should work well.

    Keep us informed of your progress.

    Ciao.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 04:35 PM