Skip to content

Game does not capture cursor in windowed mode #104

Closed

Description

@xezon

Game does not capture cursor in windowed mode. This makes native window mode (-win command line) unusable.

GenTool fixes this by using Windows ClipCursor function.

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-clipcursor

Note that ClipCursor must be lifted when minimizing game out of full screen when using 2 monitors, otherwise cursor will remain captured on main screen. This can be done by calling ClipCursor(0) on Direct3DDevice8::Reset.

Activity

  1. added
    BugSomething is not working right, typically is user facing
    GenToolRelates to GenTool
    CriticalSeverity: Minor < Major < Critical < Blocker
    ExecutableIs game code related
    on Oct 8, 2021
  2. reopened this on Dec 21, 2021
  3. ShizCalev commented on Mar 3, 2025

    @ShizCalev

    looks like the game already has the proper logic for releasing capture when minimizing. ClipCursor() is only getting called when there's specifically a directinput mouse though, which might be the actual issue

    //-------------------------------------------------------------------------
    case WM_ACTIVATE:
    {
    Int active = LOWORD( wParam );
    //
    // when window is becoming deactivated we must release mouse cursor
    // locks on our region, otherwise set the mouse limit region again
    // which will clip the cursor to our window
    //
    if( active == WA_INACTIVE )
    {
    ClipCursor( NULL );
    if (TheAudio)
    TheAudio->loseFocus();
    } // end if
    else
    {
    if( TheMouse )
    TheMouse->setMouseLimits();
    if (TheAudio)
    TheAudio->regainFocus();
    } // end else
    break;

    void DirectInputMouse::setMouseLimits( void )
    {
    //
    // extending functionality, although we may overwrite the limits set
    // from the base class
    //
    Mouse::setMouseLimits();
    //
    // when runing windowed we want to keep the mouse within the game
    // window cause it's annoying to mouse out of the window and click
    // on a background window.
    //
    if( TheDisplay && TheDisplay->getWindowed() == TRUE )
    {
    RECT windowRect;
    // get the window rect
    GetWindowRect( ApplicationHWnd, &windowRect );
    // keep the cursor clipped to these coords when running windowed
    ClipCursor( &windowRect );
    } // end if
    } // end setMouseLimits

    void Mouse::setMouseLimits( void )
    {
    m_minX = 0;
    m_minY = 0;
    if( TheDisplay )
    {
    m_maxX = TheDisplay->getWidth();
    m_maxY = TheDisplay->getHeight();
    } // end if
    } // end setMouseLimits

  4. added theissue type on Mar 4, 2025
  5. removed theissue type on Mar 4, 2025
  6. added theissue type on Mar 4, 2025
  7. added
    ZHRelates to Zero Hour
    and removed
    ExecutableIs game code related
    on Mar 4, 2025
  8. added
    EnhancementIs new feature or request
    and removed
    BugSomething is not working right, typically is user facing
    ZHRelates to Zero Hour
    on Jul 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CriticalSeverity: Minor < Major < Critical < BlockerEnhancementIs new feature or requestGenToolRelates to GenTool

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions