Thread: Using keybd_event

  1. #1
    BOT77
    Guest

    Using keybd_event

    Hello, im currently using keybd_event...

    I want it to send it to a specific window. Like a macro program


    So far I have it sending keys to whatever window is on top, thats cool and all and it works, which matters to me a lot.

    But with keybd_event can I set it to a specific window?

    EXAMPLE of Presenet:

    I have my consule application running

    Code:
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
       
    
       int main(void)
       {
    	   int end_program;
    	   int i;
    
    	   while(i<1000)
    		   i++;
    
    	   i = 0;
    		keybd_event(VK_TAB,
                        0x45,
                        KEYEVENTF_EXTENDEDKEY | 0,
                        0 );
    	   while(i<5) {
           keybd_event(66,
                        0x45,
                        KEYEVENTF_EXTENDEDKEY | 0,
                        0 );
    	   keybd_event( 66,
                          0x45,
                          KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
                          0);
    	   i++;
    	   }
    		keybd_event(VK_RETURN,
                        0x45,
                        KEYEVENTF_EXTENDEDKEY | 0,
                        0 );
    
    	scanf("%d",&end_program);
    
    	if (end_program == 1)
    	return EXIT_SUCCESS;
    
       }
    Pretty simple, NOW when i run it whatever window is on top gets the keys sent to it

    How do I make it so any window can be on top, yet it will send the keys to a specific application?


    BOT77

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Keyboard input is handled by whichever window has the focus. SetForegroundWindow may help but you'd still need the handle of the target window to do this.

    Looks like keybd_event has been superseded by SendInput for win2k/xp.

  3. #3
    BOT77
    Guest

    better way?

    So what would be a better way of doing this?

    FindWindow then sendmessage to send keys to it?

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Try out Win32 Hooks

    gg

Popular pages Recent additions subscribe to a feed