Thread: (Windows) Send keyboard and mouse to another program?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    1

    (Windows) Send keyboard and mouse to another program?

    I already know how to send mouse co-ordinates and click with the mouse (using SendInput()), however it does not work.

    I would also like to know how to send text (several words, though, not single keys) to other programs.

    As a side note, if anyone knows how to take words from an image (like text-recognition), I'd like to know that too.

    Thanks.

    I have this code to move and click the mouse:
    Code:
    int x, y;
    double fScreenWidth  = ::GetSystemMetrics(SM_CXSCREEN)-1;
    double fScreenHeight = ::GetSystemMetrics(SM_CYSCREEN)-1;
    double fx = x*(65535.0f/fScreenWidth);
    double fy = y*(65535.0f/fScreenHeight);
    INPUT Input = {0};
    Input.type        = INPUT_MOUSE;
    Input.mi.dwFlags  = MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE; // Move to the co-ordinates
    Input.mi.dx = fx;
    Input.mi.dy = fy;
    ::SendInput(1,&Input,sizeof(INPUT));                       // Send the input
    ::ZeroMemory(&Input,sizeof(INPUT));                        // Clear the memory used
    Input.mi.dwFlags  = MOUSEEVENTF_LEFTDOWN;
    ::SendInput(1,&Input,sizeof(INPUT));                       // Send the input
    ::ZeroMemory(&Input,sizeof(INPUT));                        // Clear the memory used
    Input.type        = INPUT_MOUSE;
    Input.mi.dwFlags  = MOUSEEVENTF_LEFTUP;
    ::SendInput(1,&Input,sizeof(INPUT));                       // Send the input
    ::ZeroMemory(&Input,sizeof(INPUT));                        // Clear the memory used
    and although I have included windows.h; my compiler claims that INPUT and INPUT_MOUSE have not been declared. This is quite confusing...
    Edit: My compiler is Dev-C++ 4.9.9.2
    Last edited by Chrisname; 06-08-2009 at 01:34 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting keyboard and mouse in linux
    By sameer.nalwade in forum C Programming
    Replies: 3
    Last Post: 11-22-2008, 04:24 AM
  2. how to handle keyboard and mouse events for all windows
    By manav-II in forum Windows Programming
    Replies: 3
    Last Post: 08-25-2008, 09:03 AM
  3. Virtual keys
    By Arkanos in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2005, 10:00 AM
  4. Game Design Topic #2 - Keyboard or Mouse?
    By TechWins in forum Game Programming
    Replies: 4
    Last Post: 10-08-2002, 03:34 PM
  5. What would you like in a interface?
    By commanderrulz in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-29-2002, 05:29 AM