• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Directinput vs GetCursorPos

Status
Not open for further replies.
Level 10
Joined
Sep 14, 2007
Messages
227
So, I tried directinput and GetCursorPos. I'm not sure what funcion I should choose.

Directinput - The main problem is with directinput, that it only has mouse delta position (position movement). In oder to, create mouse X/Y I need to create my own cursor position, but in the end I need windows position to be same as directinput and It's kind a headache. But it has one big plus that allows to have different cursor speed from windows at the same time.

GetCursorPos - The biggest plus it is very easy used especialy with ScreenToClient (that sets my coordinates that I get from GetCursorPos to client coordinates). And I have feeling that warcraft 3, world of warcraft, heroes of newarth using GetCursorPos. Why? I made few tests in windowed mode and I saw that they are effected by windows cursor speed, also they perfectly fallows windows cursor. Only world of warcraft has its own cursor speed, but I have feeling they only change windows cursor speed then u are at game.

By the way Somewhy my GetCursorPos doesn't follow perfectly my client cursor movement

Code:
tagPOINT point;

GetCursorPos(&point);
ScreenToClient(hwnd, &point);

m_mouseX = point.x;
m_mouseY = point.y;

//m_mouseX/Y my final client cursor coordinates

So any suggestions, ideas?
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
Use a Windows Message Loop (google it for info) for keyboard and mouse input. DirectInput is deprecated and Microsoft no longer encourages its use.

The idea is to not use the windows cursor but render your own inside the display buffer. When you focus on the program you disable the standard window cursor and then lock a virtual cursor inside your game display buffer. This might not be useful for your purposes but is a necessity for FPS/TPS games where you want mouse input to control camera/aim.

A mouse sends you a delta x and delta y as well as button change events. It does not send you absolute positions and instead the delta is used by the OS to come to some form of absolute position. You can prove this by holding your mouse on a treadmill and it will still keep sending delta changes even though the windows cursor position will be at the edge of the display.
 
Level 10
Joined
Sep 14, 2007
Messages
227
Ty for answer :).
Yea, I know that I need to create my own rendering cursor. But any way I need to keep my rendering cursor coordinates same as OS cursor. Because in window mode, then I leave my rendering part, I need Os cursor to appear. So I guess I will keep with windows cursor :).

By the way maybe there's a function that can hide cursor not in client, but then it hits specife clinet area?

I tried to manipulate ShowCursor function to show it only in specife client area, but it doesn't work.

It's some numbers explanation of code.
889.0f - screenWidth (same as m_screenWidth, just for testing purpose
500.0f - screenHeight (same as m_screenHeight, just for testing purpose)

873.0f - screenWidth with clipped windows boards.
462.0f - screenHeight with clipped windows boards.


Code:
tagPOINT point, point2;
GetCursorPos(&point);
ScreenToClient(hwnd, &point);

tagRECT rect;
GetClientRect(hwnd, &rect);

m_mouseX = (int)(((float)point.x * 889.0f / 873.0f)+0.5f);
m_mouseY = (int)(((float)point.y * 500.0f / 462.0f)+0.5f);

static bool con = false;
if(((m_mouseX<0) || (m_mouseX>m_screenWidth) || (m_mouseY<0) || (m_mouseY>m_screenHeight))&&(con==false)) {cout <<"out"<<endl;ShowCursor(true);con = true;}
if(((m_mouseX>0) && (m_mouseX<m_screenWidth) && (m_mouseY>0) && (m_mouseY<m_screenHeight))&&(con==true)) {cout <<"in"<<endl;ShowCursor(false);con = false;}

Conditions works perfectly, only ShowCursor does nothing.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
I need Os cursor to appear. So I guess I will keep with windows cursor :).
I recall seeing talk about you being able to set the OS cursor position. In any case you generally want your cursor to stay stuck to the window when playing games in windowed mode to prevent accidental click of things outside the game.

I am not an expert in such an area.
 
Status
Not open for further replies.
Top