Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if mouse buttons are swapped or not in C++

I want to send some mouse click messages to a specified window of another program. I currently use WM_LBUTTONUP and WM_LBUTTONDOWN messages whose works fine.

These messages performs exactly same way regardless of a user's mouse button settings. Oppose from it, I want to know if user has swapped mouse buttons from mouse settings control panel.

I researched and found SwapMouseButton function, it works fine but I don't want to swap mouse buttons actually and I just want to know whether it is previously swapped or not.

From MSDN:

If the meaning of the mouse buttons was reversed previously, before the function was called, the return value is nonzero.

I can get the information I want this way, but it also restores them to original state of mouse buttons. I only want to check and not to restore to original state.

I currently call this function like:

SwapMouseButton(FALSE);

I like to know any other alternative way (something like SystemParametersInfo) to only check (not to also restore) whether mouse buttons has previously swapped by user.

Basically, what I want to do is simulate a primary mouse button click and a secondary mouse button click according to user's mouse button meanings.

For example, when I simulate a primary mouse button click, and if user has swapped the mouse buttons, right mouse click should simulate, otherwise left, as usual. There are no messages exist called WM_PRIMARY... and WM_SECONDARY... for me to do what I want.

Thanks in advance.

like image 524
GTAVLover Avatar asked Aug 11 '17 06:08

GTAVLover


People also ask

Is mouse 1 Left or right?

MB1 (mouse button 1) is the left button. MB2 (mouse button 2) is the middle button. MB3 (mouse button 3) is the right button.

Can you swap the mouse buttons?

To change how the mouse buttons work In the search box, type mouse, and then click Mouse. Click the Buttons tab, and then do any of the following: To swap the functions of the right and left mouse buttons, under Button configuration, select the Switch primary and secondary buttons check box.

Why are my left and right mouse buttons switched?

Right-click on the dropdown box and right-click on Left to restore the left mouse button. Remember, your mouse buttons are reversed because usually, we would left-click to change settings. Windows 7, Vista, and 8 users will see a box that reads Switch primary and secondary buttons. Uncheck that box if checked.


1 Answers

You can use GetSystemMetrics with SM_SWAPBUTTON parameter value.

SM_SWAPBUTTON 23

Nonzero if the meanings of the left and right mouse buttons are swapped; otherwise, 0.

like image 171
DAle Avatar answered Oct 18 '22 21:10

DAle