Windows mouse message processing and keyboard simulation functions, windows functions

Source: Internet
Author: User

Windows mouse message processing and keyboard simulation functions, windows functions

1. mouse coordinates

 BOOL GetWindowRect (

HWNDHWnd,
LPRECT LpRect
);

RECT x; // defines a two-dimensional array x

: GetWindowRect (hwnd, & x );

 

Point p; // x, y rect x pointer

GetCursorPos (& p); // obtains the coordinate pointer of the current mouse.

SetCursorPos (x + r1.left, y + r1.top); // you can specify the next mouse coordinate pointer.

SetCursorPos (p. x, p. y); // restore the mouse coordinates

 

2. Simulate mouse messages


LRESULT SendMessage (
HWND HWnd,
UINT Msg,
WPARAM WParam,
LPARAM LParam
); 

Int x = ?, Y = ?;

// Y <16) + x =LParam

//LParam can be obtained by SPY ++ interception or computed

// Eg. x = 655; y = 577 lparam 0x0241028f

// 0x0172 01f3

// Y = 370 x = 499

Left-click simulation:

SendMessage (hwnd, WM_LBUTTONDOWN, 0, (y <16) + x );


SendMessage (hwnd, WM_LBUTTONUP, 0, (y <16) + x );

Double-click simulation with the left button:

SendMessage (hwnd,WM_LBUTTONDBLCLK, 0, (y <16) + x );

 

Right-click simulation:

SendMessage (hwnd, WM_RBUTTONDOWN, 0, (y <16) + x );


SendMessage (hwnd, WM_RBUTTONUP, 0, (y <16) + x );

Right-click simulation:

SendMessage (hwnd,WM_RBUTTONDBLCLK, 0, (y <16) + x );

 

2. mouse events

 

VOID mouse_event(  DWORD dwFlags,   DWORD dx,   DWORD dy,   DWORD dwData,   DWORD dwExtraInfo);


Left-click message:
Mouse_event (mouse_event_LEFTUP,); // The first parameter cursor operation status


Mouse_event (mouse_event_LEFTDOWN, 0, 0, 0 );

Left-click message:

Mouse_event (mouse_event_LBUTTONDBLCLK, 0, 0, 0 );

 

 

Right-click message
Mouse_event (MOUSEEVENTF_REFTUP, 0, 0, 0 );


Mouse_event (MOUSEEVENTF_LEFTDOWN, 0, 0, 0 );

 

 

Right-click a message:
Mouse_event (mouse_event_RBUTTONDBLCLK, 0, 0, 0 );

Keyboard simulation functions

VOID keybd_event (

BYTEBVk,
BYTEBScan,
DWORDDwFlags,
PTRDwExtraInfo
);

Call:

Keybd_event (13, 0, 0, 0); // press enter for the first parameter key value 13

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.