[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Windows Simulate Mouse Left Click

Posted on 2006-11-28
1
Medium Priority
?
1,422 Views
Last Modified: 2008-01-09
Hi , how do I simulate a mouse left click (in windows) ?

ie. when i run this code , it is exactly as if the user has clicked the left mouse button ?

(please don't send me an msdn page)

Thank you,

Mark
0
Comment
Question by:Paladin_VB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 6

Accepted Solution

by:
SeanDurkin earned 280 total points
ID: 18030467
If you want to simulate a mouse-click in Windows, I recommend using the mouse_event() function, specifying the MOUSEEVENTF_ABSOLUTE and MOUSEEVENTF_LEFTDOWN flags. However, I think you need to move the cursor to that position before you simulate the click, so you should throw in a SetCursorPos() function, just to be safe:

int coordX, coordY;

// sets the mouse's position
SetCursorPos(coordX, coordY);

// simulates the click
mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN, (DWORD) coordX, (DWORD) coordY, 0, 0);
// use a pause, if you wish
mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTUP,      (DWORD) coordX, (DWORD) coordY, 0, 0);


While I realize you said don't print MSDN pages, there are parameters of the mouse_event() function that I didn't use, and you may wish to, so here are the pages to the functions I used:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/mouseinput/mouseinputreference/mouseinputfunctions/mouse_event.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/cursors/cursorreference/cursorfunctions/setcursorpos.asp

This should do the trick, although some may also recommend the SendInput() function, but trust me, the mouse_event() function works fine for me.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question