Thread: Mouse Events

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    60

    Mouse Events

    Hello,
    I've been trying to find a way to simulate mouse events.
    I already know how to change cursor's position, (using setcursorpos()), but i can't find out how to send mouse button events (press right click etc..)

    May someone help me please?

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I believe you manually have to send messages.
    The messages should be WM_LBUTTONDBBLCLK, WM_LBUTTONDOWN, WM_LBUTTONUP, WM_RBUTTONDBLCLK,, WM_RBUTTONDOWN and WM_RBUTTONUP I believe.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Codebot
    Join Date
    Jun 2004
    Location
    Toronto
    Posts
    195
    Hello.

    Seems to me that you want to use the SendInput function. It simulates everything (keyboard and Mouse events). Basically you just fill out an INPUT struct, pass it in and watch it go.

    Code:
    INPUT mouseInput;
    
    memset(&mouseInput, 0, sizeof(INPUT));
    mouseInput.type = INPUT_MOUSE;
    
    // Move a mouse Cursor
    mouseInput.mi.dx = newMouseXCoords;
    mouseInput.mi.dy = newMouseYCoords;
    
    // Click
    mouseInput.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
    
    
    // Fire Event
    SendInput(1, &mouseInput, sizeof(INPUT));
    NOTE: a Click is essentially a Mouse DOWN event followed by a Mouse UP event. If you dont send a Mouse UP event then your cursor will be treated as having the mouse button down.
    Founder and avid member of the Internationsl Typo Associateion

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Watch for mouse events
    By belhifet in forum Linux Programming
    Replies: 2
    Last Post: 04-10-2007, 11:12 AM
  2. Mouse Events
    By disruptor108 in forum C# Programming
    Replies: 0
    Last Post: 01-23-2007, 11:40 PM
  3. API for mouse events?
    By jsimpson in forum C Programming
    Replies: 0
    Last Post: 03-08-2006, 11:38 PM
  4. capturing mouse events
    By leojose in forum Windows Programming
    Replies: 7
    Last Post: 06-06-2005, 10:36 PM
  5. Mouse Events
    By Jubba in forum Windows Programming
    Replies: 1
    Last Post: 10-30-2003, 12:03 PM