Skip to content

LockMouse

Narta Xaymar Dirks edited this page Nov 1, 2026 · 1 revision

LockMouse

LockMouse:Void window:Int32=0
Parameter Mode Type Default Description
window In Int32 0 Handle of the window or gadget to keep the pointer in. Optional, 0 is the window that Graphics created.

Description

Keeps the pointer inside a window until UnlockMouse is called. This is what a first person camera or a map that scrolls at the screen edge needs: the pointer cannot leave and click on something else.

With the default of 0 the pointer is kept in the window that Graphics or Graphics3D created. With the handle of a window or gadget made by CreateWindow, CreateCanvas and friends, the pointer is kept inside the area of that window (the part inside its frame) or gadget instead. The area follows the window when it is moved or resized, and the lock ends by itself when the window or gadget is freed.

The lock does not change what MouseX, MouseY, MouseXSpeed and MouseYSpeed report, only where the pointer can go. It works together with MoveMouse, HidePointer and RawInput. Losing the focus does not end the lock: the pointer is free while another program is in front and is kept again when the window gets the focus back. Calling LockMouse again moves the lock to the new window. Without a graphics window the call is remembered and applies as soon as one is there.

Differences

  • This is a BlitzLLVM extension: the original has no such command.

Examples

Graphics 640, 480, 0, 2
SetBuffer BackBuffer()
LockMouse
HidePointer
While Not KeyHit(1)
	Cls
	Text 10, 10, "The pointer cannot leave the window. Escape ends"
	Text 10, 30, "Speed: " + MouseXSpeed() + ", " + MouseYSpeed()
	Flip
Wend
UnlockMouse
ShowPointer

Related Commands

FlushMouse, GetMouse, LastMouseDevice, MouseChanged, MouseDeviceConnected, MoveMouse, UnlockMouse, WaitMouse

Home · Command Index



Differences
Language Features
BlitzBasic
Blitz3D
BlitzPlus

Clone this wiki locally