diff --git a/ClassicalSharp/Game/InputHandler.cs b/ClassicalSharp/Game/InputHandler.cs index 0a0933639..e4405f671 100644 --- a/ClassicalSharp/Game/InputHandler.cs +++ b/ClassicalSharp/Game/InputHandler.cs @@ -288,11 +288,12 @@ namespace ClassicalSharp { } static int[] viewDistances = { 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 }; + Key lastKey; void KeyDownHandler( object sender, KeyboardKeyEventArgs e ) { Key key = e.Key; if( SimulateMouse( key, true ) ) return; - if( key == Key.F4 && (game.IsKeyDown( Key.AltLeft ) || game.IsKeyDown( Key.AltRight )) ) { + if( IsShutdown( key ) ) { game.Exit(); } else if( key == Keys[KeyBinding.Screenshot] ) { game.screenshotRequested = true; @@ -300,6 +301,15 @@ namespace ClassicalSharp { if( !HandleBuiltinKey( key ) && !game.LocalPlayer.HandleKeyDown( key ) ) HandleHotkey( key ); } + lastKey = key; + } + + bool IsShutdown( Key key ) { + if( key == Key.F4 && (lastKey == Key.AltLeft || lastKey == Key.AltRight) ) + return true; + // On OSX, Cmd+Q should also terminate the process. + if( !OpenTK.Configuration.RunningOnMacOS ) return false; + return key == Key.Q && (lastKey == Key.WinLeft || lastKey == Key.WinRight); } void HandleHotkey( Key key ) { diff --git a/ClassicalSharp/Utils/Utils.cs b/ClassicalSharp/Utils/Utils.cs index 0fa6373f7..d142bcb38 100644 --- a/ClassicalSharp/Utils/Utils.cs +++ b/ClassicalSharp/Utils/Utils.cs @@ -40,9 +40,8 @@ namespace ClassicalSharp { /// Returns the next highest power of 2 that is ≥ to the given value. public static int NextPowerOf2( int value ) { int next = 1; - while( value > next ) { + while( value > next ) next <<= 1; - } return next; } @@ -53,10 +52,7 @@ namespace ClassicalSharp { /// Returns a string with all the colour codes stripped from it. public static string StripColours( string value ) { - if( value.IndexOf( '&' ) == -1 ) { - return value; - } - + if( value.IndexOf( '&' ) == -1 ) return value; char[] output = new char[value.Length]; int usedChars = 0;