Difference between revisions of "Mouse Lock API Points of Interest"

From CDOT Wiki
Jump to: navigation, search
(WIN32 API)
Line 1: Line 1:
 
This page is for tracking different parts of the Firefox code that relate to the mouse in different ways.
 
This page is for tracking different parts of the Firefox code that relate to the mouse in different ways.
 +
 +
I suggest looking at widget/src/*/nsWindow.cpp for starters. It seems like the OS-Specific mouse stuff is all done in there.
  
 
==WIN32 API==
 
==WIN32 API==
 
* [http://mxr.mozilla.org/mozilla-central/source/widget/src/windows/nsWindow.cpp#3874 Internal mouse event tracking]
 
* [http://mxr.mozilla.org/mozilla-central/source/widget/src/windows/nsWindow.cpp#3874 Internal mouse event tracking]
 +
 +
Here's some code that actually locks the mouse into a rectangle with no width or height in the center of the screen in WIN32.
 +
 +
RECT windowRect;
 +
::GetWindowRect(mWnd, &windowRect);
 +
nsIntPoint mousePos;
 +
mousePos.x = windowRect.right/2;
 +
mousePos.y = windowRect.bottom/2;
 +
RECT mouseRect = { mousePos.x, mousePos.y, mousePos.x, mousePos.y };
 +
ClipCursor(&mouseRect); // Forces the mouse to be only within that rectangle on the screen, giving it no width and height means it's locked.

Revision as of 00:13, 11 November 2011

This page is for tracking different parts of the Firefox code that relate to the mouse in different ways.

I suggest looking at widget/src/*/nsWindow.cpp for starters. It seems like the OS-Specific mouse stuff is all done in there.

WIN32 API

Here's some code that actually locks the mouse into a rectangle with no width or height in the center of the screen in WIN32.

RECT windowRect;

GetWindowRect(mWnd, &windowRect);

nsIntPoint mousePos; mousePos.x = windowRect.right/2; mousePos.y = windowRect.bottom/2; RECT mouseRect = { mousePos.x, mousePos.y, mousePos.x, mousePos.y }; ClipCursor(&mouseRect); // Forces the mouse to be only within that rectangle on the screen, giving it no width and height means it's locked.