Archived

This topic is now archived and is closed to further replies.

Getting the Mousestatus

This topic is 5580 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How can I get the current Mousestatus in C++? Exists there any functions how i can get the current Status of the Mouse. The Information I need is e.g. if the LeftMouse-Button is pressed. Peter Gmeiner

Share this post


Link to post
Share on other sites
It depends on the operating system. On Windows take a look at WM_LBUTTONDBLCLK, WM_LBUTTONDOWN, WM_LBUTTONUP and WM_NCLBUTTONDBLCLK, WM_NCLBUTTONDOWN, WM_NCLBUTTONUP - and a few others.

Share this post


Link to post
Share on other sites
I found a way to get it, but it does not work well. I used the MouseInterrupt with the following ASM-Statement:

_asm
{
mov ax, 3
int 33h
}

when i execute this Statement then at the line were the Interrupt is called, I get an Access Violation. Does anyone know what the reason for this Access Violation could be??

Peter Gmeiner

Share this post


Link to post
Share on other sites
Your operating system probably doesn''t allow the int instruction in user programs. You''ll need to use the OS specific functions to get the mouse state.

Share this post


Link to post
Share on other sites
do you know how such a OS specific c-function for the Windows-Operating System? I know that there is a function like int68x() but it seems that this one is not a part ov the visual studio from microsoft. Perhaps anyone knows such a function?

Peter Gmeiner

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you want to get the mouse info on a Windows machine, you have to use the Win32 API, like LessBread said. You could also use DirectInput. C++ has no concept of a "mouse", and you won''t be able to use interupts, so you have to use some library.

Share this post


Link to post
Share on other sites
In Win32:

To get the position, use GetCursorPos.

To get button status (including mouse buttons), use GetAsyncKeyState or GetKeyState.


BOOL GetCursorPos(LPPOINT lpPoint);
SHORT GetAsyncKeyState(int vKey);
SHORT GetKeyState(int vKey);


You''ll want to read the documentation for these functions, especially the key states, as key press data is actually a flag within the returned value.

Share this post


Link to post
Share on other sites