C++ keybd_event code

This is a discussion on C++ keybd_event code within the Windows Programming forums, part of the Platform Specific Boards category; Hi i'm trying to understand keybd_event a little more, and was testing it on other programs and find that it ...

  1. #1
    adr
    adr is offline
    Registered User
    Join Date
    Dec 2005
    Posts
    155

    C++ keybd_event code

    Hi i'm trying to understand keybd_event a little more, and was testing it on other programs and find that it doesnt do the same as it would if I press the keys myself. On word pad it seems to do what I tell it to do in code fine but when I use it on other programs it doesnt do the same.

    For example
    Code:
    keybd_event(VK_NUMPAD0,60,0,0); 
    keybd_event(VK_NUMPAD0,60, KEYEVENTF_KEYUP, 0);
    press the Numpad 0 making a 0 in word pad but when I use the same way on another program that used the numpad 0 to do things it doesnt react as if I was to just press the key. Tried using spy++ to see what it got, and I found it had a WM_CHAR in the middle of the WM-keyup and down. The Char showed 2 differnt things when I used either the code above and when I just pressed the key myself. Was giving me a wParam 0x00000030 and a lParam of 0x00520001 with a normal pressing and a wParam 0x00000030 and lParam of 0x003c0001 when I used that code above. I tried look it up on NSDM but I kinda dont unerstand the site and was hoping someone could help me make sencs on whats happening and could give me a little soure code to help me out on what I could fixs?

  2. #2
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I have problems with that function too. Try VK_SHIFT. It will push it, but won't let it back up.
    Sorry though, I still havn't found a solution.

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    You're supposed to push it down then up,

    Code:
    keybd_event(VK_NUMPAD0,60, KEYEVENTF_KEYDOWN | KEYEVENTF_KEYUP , 0);
    Also keybd_event() has been superseeded by SendInput() or whatever, See MSDN.

  4. #4
    adr
    adr is offline
    Registered User
    Join Date
    Dec 2005
    Posts
    155
    Quote Originally Posted by Queatrix View Post
    I have problems with that function too. Try VK_SHIFT. It will push it, but won't let it back up.
    Sorry though, I still havn't found a solution.

    Try something like this...
    Code:
      void meleft(){
       keybd_event(0x10,0,0,0);
       keybd_event(0xbc,0,0,0);
       keybd_event(0xbc,0,KEYEVENTF_KEYUP,0);
       keybd_event(0x10,0,KEYEVENTF_KEYUP,0);}

    As for the KEYEVENTF_KEYDOWN it doesnt work, "`KEYEVENTF_KEYDOWN' undeclared (first use this function)"

    Can you give me some examples for SendInput() cus I dont understand MSDN too good lol.

  5. #5
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Code:
    DWORD dwRet = 0;
    keyboard = {0, VK_RETURN, KEYEVENTF_UNICODE, NULL, &dwRet };
    INPUT input[ ] = { { INPUT_KEYBOARD, NULL, keyboard, NULL }, NULL };
    UINT siRet = SendInput(1, &input, sizeof(input)));
    I don't know if this works (I just made it on the fly) but it should give you the idea.
    Also: SendInput() func doc

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 03:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 05:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21