C++ Get Mouse Position

Sep 27, 2013 at 9:47pm
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 Sep 27, 2013 at 9:55pm
Sep 27, 2013 at 9:52pm
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
Sep 27, 2013 at 9:55pm
Meant for C++, same deal though?
Sep 27, 2013 at 9:56pm
closed account (o3hC5Di1)
Yes, same deal.

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

All the best,
NwN
Sep 27, 2013 at 10:15pm
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/
Sep 27, 2013 at 10:22pm
Thank you very much for the help everyone!
Sep 27, 2013 at 11:12pm
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.