Check if mouse buttons are swapped or not in C++
Asked Answered
E

1

5

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.

Erminois answered 11/8, 2017 at 6:0 Comment(2)
You have asked the wrong question, and now need help with the wrong solution. You can’t simulate keyboard input with PostMessage (the same underlying principles apply to mouse input). The question you should have asked instead: "How do I automate a UI?" The answer to that question is: "Use UI Automation." One advantage of this is, that you do not need to know the user's local mouse button settings.Lon
@Lon Thanks! I will remove PostMessage. The link you provided is very useful. :-)Erminois
K
9

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.

Kosak answered 11/8, 2017 at 6:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.