Thread: sending keystroke to a program

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    1

    sending keystroke to a program

    Hello
    I am new to windows programming .
    I need your help . I want to start a
    windows program and send Y and Q
    keystrokes to it to push its buttons .

    I am using Dev C++ ver 4.0

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    # include<fstream>
    # include<string>
    # include<conio.h>
    # include<time.h>
    # include<windows.h>
    # include<tchar.h>
     main()
    {
        
          system ("start raspppoe") ;
          keybd_event('y', 0, 0, 0);
          keybd_event('y', 0, KEYEVENTF_KEYUP, 0);
          keybd_event('q', 0, 0, 0);
          keybd_event('q', 0, KEYEVENTF_KEYUP, 0);
       
      system("exit") ;
    
      return ;
    }
    it is not working ... please help me . Thanks

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Use the VkKeyScan or VkKeyScanEx functions to translate the character to a corresponding virtual key code.

    Code:
    #include<windows.h>
    
    int main(void )
    {
    	keybd_event(VkKeyScan('y'), 0, 0, 0);
    	keybd_event(VkKeyScan('y'), 0, KEYEVENTF_KEYUP, 0);
    	keybd_event(VkKeyScan('q'), 0, 0, 0);
    	keybd_event(VkKeyScan('q'), 0, KEYEVENTF_KEYUP, 0);
    
    	// or alternatively...
    		
    	keybd_event(0x59, 0, 0, 0);
    	keybd_event(0x59, 0, KEYEVENTF_KEYUP, 0);
    	keybd_event(0x51, 0, 0, 0);
    	keybd_event(0x51, 0, KEYEVENTF_KEYUP, 0);	
    	return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  3. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM