Solved

Make the mouse cursor move and click automatically

Posted on 1998-11-11
9
437 Views
Last Modified: 2013-11-20
I want to write a program which will demonstrate how to use a software. Can I make the mouse cursor move and click at specific location? It seems VC++ and VB 5.0 can only trap the signals from mouse but cannot generate them. Can anybody help me?
0
Comment
Question by:ChanKevin
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 7

Expert Comment

by:psdavis
Comment Utility
I know that you can send a message to make the mouse 'click':

Try something like...

long wParam = MAKELONG( pt.x, pt.y );
pWnd->PostMessage( WM_LBUTTONDOWN, wParam );

First, check the LBUTTONDOWN syntax out

Phillip

0
 
LVL 2

Expert Comment

by:wyy_cq
Comment Utility
step:
1.move the cursor to the position (on the screen not on the window)
 SetCursorPos(...);

2.get the window handle from the point
 WindowFromPoint(...)

3.send message to the window you get
 SendMessage( WM_LBUTTONDOWN,...);

0
 
LVL 2

Expert Comment

by:cyrilbdt
Comment Utility
I don't see sense first to use SetCursorPos since WM_LBUTTONDOWN as arguments get down position.
As help state:
"The JournalPlaybackProc hook procedure is an application-defined or library-defined callback function used with the SetWindowsHookEx function. Typically, an application uses this function to play back a series of mouse and keyboard messages recorded previously by the JournalRecordProc hook procedure. As long as a JournalPlaybackProc hook procedure is installed, regular mouse and keyboard input is disabled."
0
 
LVL 7

Expert Comment

by:psdavis
Comment Utility
Cool.  Didn't know about that one!
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 2

Expert Comment

by:wyy_cq
Comment Utility
in Win32,
a process is not permitted to hook other process's window Proc.
because every process is running in the devided memory area.

0
 
LVL 1

Expert Comment

by:payn
Comment Utility
You're right, you can't hook another process's wndproc directly, but you can hook the system, using SetWindowsHookEx. This is intended for monitoring/logging apps, CBT apps (which is what ChanKevin's apparently trying to build), etc., and it definitely can be done in Win32.

In fact, you can indirectly hook another process's windowproc. Attach a Windows system hook to CallWndProc and you'll get each message before it goes to the appropriate wndproc, or use CallWndRetProc to catch each message after the wndproc. If you want to hook a particular application, use CallWndProc, and check each message--if the message doesn't belong to the window you're hooking, ignore it.

It's quite possible to hang your system by playing with Windows hooks, of course.

Also, under NT, you need to have the appropriate privileges for this to work.

Finally, keep in mind that MFC apps tend to behave badly when you start installing CBT hooks, so if you're trying to demonstrate an MFC app you're in for some fun debugging... Just remember to always call CallNextHookEx and look at the result.

0
 
LVL 1

Accepted Solution

by:
elf_k earned 100 total points
Comment Utility
RTFM. mouse_event(...) from Platform SDK docs.

0
 

Author Comment

by:ChanKevin
Comment Utility
I don't have SDK platform docs in Hand. Can you tell me how can I get it and which page should I refer to or give me the information in details? Also, can I make the mouse automatically click on some web page links and it will link the end user to another web site?
0
 
LVL 1

Expert Comment

by:elf_k
Comment Utility
This is a part of MSDN98/Platform SDK/Mouse Input

mouse_event

The mouse_event function synthesizes mouse motion and button clicks.

Windows NT: This function has been superseded. Use SendInput instead. (superseded but not obsolete - elf.)

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 is down.
MOUSEEVENTF_LEFTUP Specifies that the left button is up.
MOUSEEVENTF_RIGHTDOWN Specifies that the right button is down.
MOUSEEVENTF_RIGHTUP Specifies that the right button is up.
MOUSEEVENTF_MIDDLEDOWN Specifies that the middle button is down.
MOUSEEVENTF_MIDDLEUP Specifies that the middle button is up.
MOUSEEVENTF_WHEEL Windows NT: Specifies that the wheel has been moved, if the mouse has a wheel. The amount of movement is given in dwData


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.
Return Values
This function has no return value.

Remarks
If the mouse has moved, indicated by MOUSEEVENTF_MOVE being set, dx and dy hold information about that motion. The information is given as absolute or relative integer values.

If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute coordinates between 0 and 65,535. The event procedure maps these coordinates onto the display surface. Coordinate (0,0) maps onto the upper-left corner of the display surface, (65535,65535) maps onto the lower-right corner.

If the MOUSEEVENTF_ABSOLUTE value is not specified, dx and dy specify relative motions from when the last mouse event was generated (the last reported position). Positive values mean the mouse moved right (or down); negative values mean the mouse moved left (or up).

Relative mouse motion is subject to the settings for mouse speed and acceleration level. An end user sets these values using the Mouse control panel application. An application obtains and sets these values with theSystemParametersInfo function.

The system applies two tests to the specified relative mouse motion when applying acceleration. If the specified distance along either the x or y axis is greater than the first mouse threshold value, and the mouse acceleration level is not zero, the operating system doubles the distance. If the specified distance along either the x or y axis is greater than the second mouse threshold value, and the mouse acceleration level is equal to two, the operating system doubles the distance that resulted from applying the first threshold test. It is thus possible for the operating system to multiply relatively-specified mouse motion along the x or y axis by up to four times.

Once acceleration has been applied, the system scales the resultant value by the desired mouse speed. Mouse speed can range from 1 (slowest) to 20 (fastest) and represents how much the pointer moves based on the distance the mouse moves. The default value is 10, which results in no additional modification to the mouse motion.

The mouse_event function is used to synthesize mouse events by applications that need to do so. It is also used by applications that need to obtain more information from the mouse than its position and button state. For example, if a tablet manufacturer wants to pass pen-based information to its own applications, it can write a dynamic-link library (DLL) that communicates directly to the tablet hardware, obtains the extra information, and saves it in a queue. The DLL then calls mouse_event with the standard button and x/y position data, along with, in the dwExtraInfo parameter, some pointer or index to the queued extra information. When the application needs the extra information, it calls the DLL with the pointer or index stored in dwExtraInfo, and the DLL returns the extra information.

Windows CE: Windows CE does not support the MOUSEEVENTF_WHEEL constant in the dwFlags parameter.

QuickInfo
  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Unsupported.
  Header: Declared in winuser.h.
  Import Library: Use user32.lib.

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 147
sum67 challenge 35 88
twoTwo  challenge 35 86
matchUp  challenge 9 71
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now