C++ Get Mouse Position

What is the command to return the position of the mouse on screen in C?
I've been searching around but can't find it.
Last edited on
closed account (o3hC5Di1)
Hi there,

That's rather complicated. Mouse pointers are part of the window manager system, therefore they are highly platform dependent. You probably need to be looking into the API of the specific platform you are targeting.

All the best,
NwN
Meant for C++, same deal though?
closed account (o3hC5Di1)
Yes, same deal.

All the best,
NwN
It seems there is a thing for this in the Winuser.h include file.
However I am not sure how to use it.
closed account (o3hC5Di1)
Since you're using windows: http://stackoverflow.com/questions/6423729/get-current-cursor-position

All the best,
NwN
Winuser.h is a child header of windows.h. Both are windows specific to the windows api.

Window API documentation can be found here : http://msdn.microsoft.com/en-us/
Thank you very much for the help everyone!
My result was a DLL for GM:S. The problem with GameMaker:Studio is that it doesn't allow you to access the mouse coordinates outside of the screen. Thus I made this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// MOUSE Screen X / Y DLL;
#include <Windows.h>
#include <WinUser.h>
#define EXPORT extern "C" _declspec(dllexport)

EXPORT double GetMouse( double mode ) {
	POINT mouse;
	GetCursorPos( &mouse );
	if ( mode == 0 ) {
		double mousex = mouse.x;
		return mousex;
	} else {
		double mousey = mouse.y;
		return mousey;
	}
}

Topic archived. No new replies allowed.