Alt+Tab Mouse Lock

User avatar
United States of America
Junior Member
Posts: 16
Joined: 10 Aug 2019
Status: Offline

Alt+Tab Mouse Lock

Post by spdr502 » 10 Aug 2019

Summary: Mouse not properly locked to the game window after alt-tabbing.

How to reproduce: After using Alt+Tab to perform a quick action outside of the game Skillwarz no longer properly locks my mouse cursor to the game window. I use full screen, have 3 monitors in the layout: Monitor 1 (Left), Monitor 2 (Center), Monitor 3 (Right). I play Skillwarz on Monitor 1. After returning to the game if I turn right I can see my player turn right and my mouse appear on Monitor 2. If I attempt to shoot it clicks on Monitor 2 and minimizes the game.

Workaround: After alt+tabbing if you open the menu (press Escape) and then exit the menu the mouse will stay locked in the game as expected.
User avatar
Latvia
Posts: 925
Joined: 29 Dec 2017
Location: Latvia
Clan: SW
Contact:
Status: Offline

Post by OneManArmy » 10 Aug 2019

I assume it has something to do with your multi monitor setup.
To lock cursor simply open menu and press Resume.
Or: https://www.youtube.com/watch?v=ZiPzUQC19zM
User avatar
United States of America
Junior Member
Posts: 16
Joined: 10 Aug 2019
Status: Offline

Post by spdr502 » 10 Aug 2019

This is the only game that does this however. Clicking in the game does not fix the issue. You have to open the menu and click any button, including resume.
User avatar
Latvia
Posts: 925
Joined: 29 Dec 2017
Location: Latvia
Clan: SW
Contact:
Status: Offline

Post by OneManArmy » 10 Aug 2019

I have one monitor and i don't have such problem.
Is it so hard to press Alt+Tab => M => Resume?
User avatar
United States of America
Posts: 466
Joined: 09 May 2018
Location: United States
Clan: OP
Contact:
Status: Online

Post by impossybull » 11 Aug 2019

P.S. The ` key (the one between Q and Esc) is also mapped to open the menu, if you are used to pressing Esc
"Practice to gain skill"
          Image
               "Think to gain strategy"

Member of Split, SWAT, Milk, RT, Dark Masters, Criminal Gamers, Fusion, Greg Heffley, and leader of OVERPOWERED.
User avatar
United States of America
Junior Member
Posts: 16
Joined: 10 Aug 2019
Status: Offline

Post by spdr502 » 14 Aug 2019

OneManArmy wrote:
10 Aug 2019
I have one monitor and i don't have such problem.
Is it so hard to press Alt+Tab => M => Resume?
Yes. Opening any menu item is a workaround. However, it's still a workaround. The bug exists and is annoying.

I've recorded a video to help further explain how the bug occurs. https://imgur.com/a/y9xtRSl
User avatar
Latvia
Posts: 925
Joined: 29 Dec 2017
Location: Latvia
Clan: SW
Contact:
Status: Offline

Post by OneManArmy » 14 Aug 2019

Problem is not in my code, but how unity handles cursor lock state when you ALT-TAB. With one monitor everything is fine, but with multiple monitors cursor can move outside and to fix such problem i have to lock cursor again - even if cursor is not unlocked (by game logic).
Theoretically i can check when game is back in focus and then call function to lock cursor again, but i am not sure if it will not cause other problems.
User avatar
United States of America
Posts: 466
Joined: 09 May 2018
Location: United States
Clan: OP
Contact:
Status: Online

Post by impossybull » 14 Aug 2019

Maybe you could add it as a Toggle On/Off option and see how it goes :?:
"Practice to gain skill"
          Image
               "Think to gain strategy"

Member of Split, SWAT, Milk, RT, Dark Masters, Criminal Gamers, Fusion, Greg Heffley, and leader of OVERPOWERED.
User avatar
Latvia
Posts: 925
Joined: 29 Dec 2017
Location: Latvia
Clan: SW
Contact:
Status: Offline

Post by OneManArmy » 18 Aug 2019

Nah, i will simply check if more then 1 display.

Code: Select all

	void OnApplicationFocus(bool inFocus){
		if (Display.displays.Length > 1){
			if(inFocus && !Cursor.visible){
				Cursor.lockState = CursorLockMode.Locked;	
			}	
		}	
	}
Theoretically should fix the problem.
User avatar
United States of America
Junior Member
Posts: 16
Joined: 10 Aug 2019
Status: Offline

Post by spdr502 » 19 Aug 2019

Thank you OMA, I look forward to this fix..a lot!
Post Reply