Hello guys. I'm having some trouble keeping the cursor in my game window. I have the following code which works quite fine:
if(GetFocus() == Game::window) {
GetCursorPos(&this->cursorPos);
ScreenToClient(Game::window, &this->cursorPos);
POINT pCopy = this->cursorPos;
if(this->cursorPos.x > windowSize.right) pCopy.x = windowSize.right;
if(this->cursorPos.x < 0) pCopy.x = 0;
if(this->cursorPos.y > windowSize.bottom) pCopy.y = windowSize.bottom;
if(this->cursorPos.y < 0) pCopy.y = 0;
if(pCopy.x != this->cursorPos.x || pCopy.y != this->cursorPos.y) {
ClientToScreen(Game::window, &pCopy);
SetCursorPos(pCopy.x, pCopy.y);
}
}
The problem now is that when i go out of the window too quickly with the mouse and click it loses focus. Is there any way to avoid this?