the SendMessage function

If you want to simulate a mouse click programatically, you must know the SendMessage function. To make your simulator work, you should understand the function well. First, the name is SendMessage, not sendMessage. The prototype of this function is:

LRESULT WINAPI SendMessage(
_In_ HWND   hWnd,
_In_ UINT   Msg,
_In_ WPARAM wParam,
_In_ LPARAM lParam
);

 

To simulate a mouse click, you should use the following code:

SendMessage(hwnd,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM(x,y));

SendMessage(hwnd,WM_LBUTTONUP,0,MAKELPARAM(x,y));

 

The confusing point is the third parameter which indicates “whether various virtual keys are down”. However, for a mouse click, this parameter seems redundant considering the second parameter. Some programmers may write the following code:

SendMessage(hwnd,WM_LBUTTONDOWN,0,MAKELPARAM(x,y));

SendMessage(hwnd,WM_LBUTTONUP,0,MAKELPARAM(x,y));

 

or,

SendMessage(hwnd,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM(x,y));

SendMessage(hwnd,WM_LBUTTONUP,MK_LBUTTON,MAKELPARAM(x,y));

 

Unfortunately, both the above two do not work. Also pay attention to the x,y coordinates, which are the positions of the click relative to the left-top of hwnd.

Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:

Comments are closed, but trackbacks and pingbacks are open.