Getting the Mousestatus

Started by
6 comments, last by PGmeiner 21 years, 7 months ago
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
Peter Gmeiner
Advertisement
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.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
No that is not what i mean. I don''t mean any Windows-Messages just function.

Peter Gmeiner
Peter Gmeiner
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
Peter Gmeiner
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.
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
Peter Gmeiner
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.
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.

This topic is closed to new replies.

Advertisement