Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Windowed Mode + Keys

Discussion in 'Windows' started by falkenbrew, Feb 17, 2021.

  1. falkenbrew

    falkenbrew

    Joined:
    Apr 21, 2020
    Posts:
    146
    I want to be able to move the game window with the windows keys, e.g. to move it to a different screen. Windows->(left, right, up, down) how do I get these commands to work?

    I'm also confused by the fact that the games resolution stays the same when switching into full-screen but resizing works as expected (resolution changes with it).

    Is there some simple setting I can make to have expected behaviour?
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,529
    Those key combinations should work as long as you're not in exclusive fullscreen mode.

    As for changing into fullscreen mode: if you want it to change the resolution at the same time, just Screen.SetResolution call instead.
     
  3. falkenbrew

    falkenbrew

    Joined:
    Apr 21, 2020
    Posts:
    146
    Fantastic!

    I started off with googling the problem and the solutions suggested some really weird things. I ended up with code like this (DO NOT DO THIS):
    Code (CSharp):
    1. IEnumerator _FixResolutionFullscreen()
    2.     {
    3.         var currentResolution = Screen.currentResolution;
    4.         Screen.fullScreen = true;
    5.         PlayerPrefs.SetInt("full", 1);
    6.         yield return null;
    7.         yield return null;
    8.         Screen.SetResolution(currentResolution.width, currentResolution.height, true);
    9.     }
    My current solution is this:
    Code (CSharp):
    1.  
    2. public void ToggleScreen()
    3.     {
    4.         if (Screen.fullScreen)
    5.         {
    6.             Screen.SetResolution(PlayerPrefs.GetInt("winw",800), PlayerPrefs.GetInt("winh",600), false);
    7.         }
    8.         else
    9.         {
    10.             PlayerPrefs.SetInt("winw", Screen.width);
    11.             PlayerPrefs.SetInt("winh", Screen.height);
    12.             var currentResolution = Screen.currentResolution;
    13.             Screen.SetResolution(currentResolution.width, currentResolution.height, true);
    14.         }
    15.     }
    16.  
    The Windows Keys was another problem and not Unity's fault. I've learnt that my keyboard has a "gaming mode" toggled by a button. When the "gaming mode" is active, the windows-key is disabled.
     
  4. nurjahanbibi

    nurjahanbibi

    Joined:
    Jan 2, 2023
    Posts:
    1
    It sounds like you're having some trouble getting your game window to move using the windows keys, and you're also confused by the way the resolution behaves when you switch to full-screen. If you're facing some troubles figuring out how to make these changes or get the behavior you want, it might be worth seeking out some additional help. You could consider posting about your problem on platforms like Reddit, where there are often help people who might be able to offer suggestions. It's also worth looking into the game's settings to see if anything might help you get the desired behavior.
     
    Last edited: Jan 3, 2023