Search Unity

Mouse.current.leftButton.isPressed is true When WindowsPlayer Regains Focus

Discussion in 'Input System' started by javaduan, Mar 18, 2022.

  1. javaduan

    javaduan

    Joined:
    Mar 15, 2017
    Posts:
    4
    Help, In WindowsPlayer after the application regains focus Mouse.current.leftButton.isPressed is true, and first click is invalid.
     
  2. javaduan

    javaduan

    Joined:
    Mar 15, 2017
    Posts:
    4
    InputSystem.ResetDevice can resolve my problem.
     
  3. OddViz

    OddViz

    Joined:
    Dec 17, 2019
    Posts:
    9
    Thanks, I ran into the same issue and this helped, but the click that regains the focus still isn't registered, only the one after that.
     
  4. Vincent_LKB

    Vincent_LKB

    Joined:
    Apr 15, 2022
    Posts:
    5
    same issue,anyone know how to fix it?
     
  5. Jasozz

    Jasozz

    Joined:
    Oct 15, 2014
    Posts:
    13
    I'm experiencing this issue as well - LMB is held down when players re-focus the window. Quite frustrating in a survival horror game when you start dumping precious ammo as soon as you click back in.
     
  6. OddViz

    OddViz

    Joined:
    Dec 17, 2019
    Posts:
    9
    Coming back to this issue, it seems that the new Input System Package does not update the mouse status when the application is not in focus. So once you click out of the application, that click is registered, and the mouse status is frozen until AFTER the application is re-focused. So you click once to regain focus, the mouse is still registered as having the left mouse button pressed, and stays that way until you click it a second time. It's likely this issue affects other input devices as well, though I haven't checked.

    I worked around this by switching to using the "Both" option in the Active Input Handling dropdown in the Player settings, and using the old Input Manager's Input.mousePosition and Input.GetMouseButton(0) / Input.GetMouseButtonDown(0) instead of Mouse.current.position.ReadValue() and Mouse.current.leftButton.isPressed / Mouse.current.leftButton.wasPressedThisFrame.
     
  7. Vincent_LKB

    Vincent_LKB

    Joined:
    Apr 15, 2022
    Posts:
    5
    unity 2019.4.40 is fixed