inpClipMouseToWindow

Confines mouse cursor to window client area (prevents cursor from leaving window). Takes no parameters. Returns nothing.

Input

Parameters & Returns

Parameters

This function takes no parameters.

Returns

Void

Quick Summary

Confines mouse cursor to window client area (prevents cursor from leaving window). Takes no parameters. Returns nothing.

Technical Exegesis...

Confines mouse cursor to window client area (prevents cursor from leaving window). Takes no parameters. Returns nothing. Uses Win32 ClipCursor API to restrict mouse movement to window bounds.

This function clips mouse. Mouse clipping: prevents cursor from moving outside window rectangle, cursor hits invisible wall at window edges, useful for FPS camera control and immersive games, user cannot accidentally click outside window during gameplay.

Example

Example.bam
; FPS game setup - clip and hide cursor at start
Function SetupFPSControls()
    inpClipMouseToWindow()      ; Confine cursor to window
    inpSetMouseVisible(False)   ; Hide cursor for immersion
EndFunction

; Call at game start
SetupFPSControls()

; Main FPS camera control loop
camYaw! = camYaw! + inpGetMouseDeltaX() * sensitivity!
camPitch! = camPitch! - inpGetMouseDeltaY() * sensitivity!
; ... apply camYaw! / camPitch! to your view or aim reticle ...

; Release cursor when showing pause menu
If inpIsKeyHit(VKEY_ESCAPE) Then
    paused% = Not paused%
    If paused% Then
        inpUnclipMouse()         ; Free cursor for menu
        inpSetMouseVisible(True)  ; Show cursor
    Else
        inpClipMouseToWindow()    ; Re-clip for gameplay
        inpSetMouseVisible(False) ; Hide cursor
    EndIf
EndIf

; RTS game - clip when window active
Function OnWindowActivate()
    If gameStarted% And Not menuActive% Then
        inpClipMouseToWindow()  ; Clip when window gains focus
    EndIf
EndFunction

Function OnWindowDeactivate()
    inpUnclipMouse()  ; Release when window loses focus
EndFunction

; Handle window resize - re-clip to new window size
Function OnWindowResize()
    If mouseCli pped% Then
        inpClipMouseToWindow()  ; Update clip rectangle to new size
    EndIf
EndFunction

; Toggle clipping with debug key
If inpIsKeyHit(VKEY_F12) Then
    debugUnclipped% = Not debugUnclipped%
    If debugUnclipped% Then
        inpUnclipMouse()
        Print "Mouse unclipped (debug mode)"
    Else
        inpClipMouseToWindow()
        Print "Mouse clipped to window"
    EndIf
EndIf

; Windowed game with focus detection
While running%
    sysUpdateEvents()

    If inpIsWindowActive() Then
        ; Window active - clip mouse if not paused
        If Not paused% And Not mouseClipped% Then
            inpClipMouseToWindow()
            mouseClipped% = True
        EndIf
    Else
        ; Window inactive - release mouse
        If mouseClipped% Then
            inpUnclipMouse()
            mouseClipped% = False
        EndIf
    EndIf

    ; ... game logic ...
Wend