byte mouse_lock_on_off = 0;
void lock_mouse(var on_off)
{
mouse_lock_on_off = (byte)(on_off != NULL);
byte _toggle = window_focus;
RECT temp_rect;
GetClientRect(hWnd, &temp_rect);
ClientToScreen(hWnd, &temp_rect);
ClientToScreen(hWnd, &temp_rect.right);
if(_toggle)
{
ClipCursor(&temp_rect);
}
while(mouse_lock_on_off)
{
GetClientRect(hWnd, &temp_rect);
ClientToScreen(hWnd, &temp_rect);
ClientToScreen(hWnd, &temp_rect.right);
if(_toggle && !window_focus)
{
_toggle = 0;
ClipCursor(NULL);
}
if(!_toggle && window_focus)
{
_toggle = 1;
ClipCursor(&temp_rect);
}
wait(1);
}
ClipCursor(NULL);
}
var mouse_lock = 0;
function lockmouse()
{
if (mouse_lock == 0) { mouse_lock = 1; lock_mouse(1); }
}
function unlockmouse()
{
if (mouse_lock == 1) { mouse_lock = 0; lock_mouse(0); }
}