?
Solved

fake mouse click

Posted on 2000-02-07
3
Medium Priority
?
231 Views
Last Modified: 2013-12-03
Hi,

I am trying to write a C++ program for Win95/NT that can fool any other application into thinking that the left mouse button has been pressed. Any ideas about how this can be done will be greatly appreciated.
0
Comment
Question by:bjovanovic
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 800 total points
ID: 2497789
You can do this by using the 'mouse_event()' API, it's designed for this purpose - here's the description from the VC++ docs:

mouse_event  
The mouse_event function synthesizes mouse motion and button clicks.

Windows NT only: This function has been superseded. Use MouseEventEx instead.

VOID mouse_event( DWORD dwFlags,
 // flags specifying various motion/click variants
 
DWORD dx,
 // horizontal mouse position or position change
 
DWORD dy,
 // vertical mouse position or position change
 
DWORD dwData,
 // amount of wheel movement
 
DWORD dwExtraInfo
 // 32 bits of application-defined information
 
);
 


Parameters
dwFlags

A set of flag bits that specify various aspects of mouse motion and button clicking. The bits in this parameter can be any reasonable combination of the following values: Value
 Meaning
 
MOUSEEVENTF_ABSOLUTE
 Specifies that the dx and dy parameters contain normalized absolute coordinates. If not set, those parameters contain relative data: the change in position since the last reported position. This flag can be set, or not set, regardless of what kind of mouse or mouse-like device, if any, is connected to the system. For further information about relative mouse motion, see the following Remarks section.
 
MOUSEEVENTF_MOVE
 Specifies that movement occurred.
 
MOUSEEVENTF_LEFTDOWN
 Specifies that the left button changed to down.
 
MOUSEEVENTF_LEFTUP
 Specifies that the left button changed to up.
 
MOUSEEVENTF_RIGHTDOWN
 Specifies that the right button changed to down.
 
MOUSEEVENTF_RIGHTUP
 Specifies that the right button changed to up.
 
MOUSEEVENTF_MIDDLEDOWN
 Specifies that the middle button changed to down.
 
MOUSEEVENTF_MIDDLEUP
 Specifies that the middle button changed to up.
 
MOUSEEVENTF_WHEEL
 Windows NT only: Specifies that the wheel has been moved, if the mouse has a wheel. The amount of movement is given in dwData
 


The flag bits that specify mouse button status are set to indicate changes in status, not ongoing conditions. For example, if the left mouse button is pressed and held down, MOUSEEVENTF_LEFTDOWN is set when the left button is first pressed, but not for subsequent motions. Similarly, MOUSEEVENTF_LEFTUP is set only when the button is first released.

dx

Specifies the mouse’s absolute position along the x-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is given as the mouse’s actual x-coordinate; relative data is given as the number of mickeys moved. A mickey is the amount that a mouse has to move for it to report that it has moved.

dy

Specifies the mouse’s absolute position along the y-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is given as the mouse’s actual y-coordinate; relative data is given as the number of mickeys moved.

dwData

If dwFlags is MOUSEEVENTF_WHEEL, then dwData specifies the amount of wheel movement. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user. One wheel click is defined as WHEEL_DELTA, which is 120.

If dwFlags is not MOUSEEVENTF_WHEEL, then dwData should be zero.

dwExtraInfo

Specifies an additional 32-bit value associated with the mouse event. An application calls GetMessageExtraInfo to obtain this extra information.
0
 

Author Comment

by:bjovanovic
ID: 2497820
I am impressed. This person answered the question in 30 sec.

Thanks!
0
 
LVL 86

Expert Comment

by:jkr
ID: 2497841
<s>
30s?

From: bjovanovic  Title: "fake mouse click"  
Points: 20  Date: Monday, February 07 2000 - 09:31PM CET  

From: jkr
 Date: Monday, February 07 2000 - 08:41PM CET  

50min before you asked ;-)

(no, to be honest, this is a bug with the EE clock <g>)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
If you are looking for an automated solution for backup single or multiple Office 365 user mailboxes to Outlook data file, then you can use Kernel Office 365 Backup & Restore tool. Go through the video to check out the steps to backup single or mult…
Suggested Courses

601 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