From 70a0d13c50a5f79b6094244c9fe11caf37c723ae Mon Sep 17 00:00:00 2001 From: Bob Date: Mon, 22 Feb 2010 14:00:38 +1300 Subject: [PATCH] keyboard input (SDL) --- OpenRa.Game/Game.cs | 18 +++++++++--------- OpenRa.Gl/GraphicsDevice.cs | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index 2c36f8ac6d..42156bcc61 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -317,18 +317,14 @@ namespace OpenRa public static void HandleKeyDown( KeyEventArgs e ) { - int sync = Game.world.SyncHash(); + //int sync = Game.world.SyncHash(); - if( !Game.chat.isChatting ) - if( e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9 ) - Game.controller.selection.DoControlGroup( world, - (int)e.KeyCode - (int)Keys.D0, (Modifiers)(int)e.Modifiers ); - if( sync != Game.world.SyncHash() ) - throw new InvalidOperationException( "Desync in OnKeyDown" ); + //if( sync != Game.world.SyncHash() ) + // throw new InvalidOperationException( "Desync in OnKeyDown" ); } - public static void HandleKeyPress( KeyPressEventArgs e ) + public static void HandleKeyPress( KeyPressEventArgs e, Modifiers modifiers ) { int sync = Game.world.SyncHash(); @@ -336,7 +332,11 @@ namespace OpenRa Game.chat.Toggle(); else if( Game.chat.isChatting ) Game.chat.TypeChar( e.KeyChar ); - + else + if( e.KeyChar >= '0' && e.KeyChar <= '9' ) + Game.controller.selection.DoControlGroup( world, + e.KeyChar - '0', modifiers ); + if( sync != Game.world.SyncHash() ) throw new InvalidOperationException( "Desync in OnKeyPress" ); } diff --git a/OpenRa.Gl/GraphicsDevice.cs b/OpenRa.Gl/GraphicsDevice.cs index 73d10503b5..55fb0326e1 100644 --- a/OpenRa.Gl/GraphicsDevice.cs +++ b/OpenRa.Gl/GraphicsDevice.cs @@ -63,6 +63,7 @@ namespace OpenRa.GlRenderer surf = Sdl.SDL_SetVideoMode(width, height, 0, Sdl.SDL_OPENGL | (windowed ? 0 : Sdl.SDL_FULLSCREEN)); Sdl.SDL_WM_SetCaption("OpenRA", "OpenRA"); Sdl.SDL_ShowCursor(0); + Sdl.SDL_EnableUNICODE( 1 ); CheckGlError(); @@ -170,6 +171,26 @@ namespace OpenRa.GlRenderer new MouseEventArgs(lastButtonBits, 0, e.motion.x, e.motion.y, 0), Keys.None); } break; + + case Sdl.SDL_KEYDOWN: + { + var mods = ( ( e.key.keysym.mod & Sdl.KMOD_ALT ) != 0 ? Modifiers.Alt : 0 ) + | ( ( e.key.keysym.mod & Sdl.KMOD_CTRL ) != 0 ? Modifiers.Ctrl : 0 ) + | ( ( e.key.keysym.mod & Sdl.KMOD_SHIFT ) != 0 ? Modifiers.Shift : 0 ); + if( e.key.keysym.unicode != 0 ) + Game.HandleKeyPress( new KeyPressEventArgs( (char)e.key.keysym.unicode ), mods ); + + else if( mods != 0 ) + { + var keyName = Sdl.SDL_GetKeyName( e.key.keysym.sym ); + if( keyName.Length == 1 ) + Game.HandleKeyPress( new KeyPressEventArgs( keyName[ 0 ] ), mods ); + } + } break; + + case Sdl.SDL_KEYUP: + { + } break; } }