How do I check if the Left button of my mouse is currently pressed down/dragging something(I preffer the first possibility).
I tried Mouse.IsDraging,but no result.
NOTE: I handle mouse messages in my application so its no problem if its a WM,just share a way to accomplish my task.
There is a Windows API function GetAsyncKeyState()
, which despite its name is also usable to get the state of the mouse buttons. The linked documentation directly contains the answer to your question:
The
GetAsyncKeyState
function works with mouse buttons. However, it checks on the state of the physical mouse buttons, not on the logical mouse buttons that the physical buttons are mapped to. For example, the callGetAsyncKeyState(VK_LBUTTON)
always returns the state of the left physical mouse button, regardless of whether it is mapped to the left or right logical mouse button. You can determine the system's current mapping of physical mouse buttons to logical mouse buttons by callingGetSystemMetrics(SM_SWAPBUTTON)
which returnsTRUE
if the mouse buttons have been swapped.
The result type is short
, to check for the most significant bit just test whether the value is negative.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With