Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting whether mouse button is pressed 3

Status
Not open for further replies.

solla

Programmer
Feb 21, 2003
19
0
0
FR
Is there a Windows API that will tell me whether the mouse button is in the process of being pressed (i.e. is currently "down")?

(In a non-MFC app I want to know this before proceeding with an operation)
 
Hi Solla,

Search for SetWindowsHookEx API at MSDN. Hook into WH_MOUSE / WH_MOUSE_LL. All mouse event will be send to the MouseProc Callback.

Regards

-- AirCon --
 
Hi AirCon (as in Con Air??? :) )
Can you show a basic call of this SetWindowsHookEx in VB? The search on the MSDN is not too clear. I have started API programing about 2 months ago and I am familiar with the basic, i.e., EnumWindows, SendMessage, etc.

Can you show how to use the SetWindowsHookEx?
 
See also GetAsyncKeyState() Windows API function (in MSDN;).
Quotation:

Remarks
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 call GetAsyncKeyState(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.

 
>SetWindowsHookEx in VB

A keyword search in Forum222 should find some examples (I know that I've certainly posed a few in the past)
 
There is also a very direct way of figuring out whether a key or mouse button is down, though requires a hard loop to be constantly checking for it. The function GetKeyState(int) will tell you whether any key/mouse button is being pressed at a given time. You can use it like this:

byte keyState = GetKeyState(VK_MButton);
if(keyState & 128)
//mouse is down
else
//mouse is not down

Although Callback functions are most traditional, this function can come in handy when you wish to, say, use the mouse to "drag" a picture around the screen.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top