keyboard input (SDL)

This commit is contained in:
Bob
2010-02-22 14:00:38 +13:00
parent 95324e140a
commit 70a0d13c50
2 changed files with 30 additions and 9 deletions

View File

@@ -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" );
}

View File

@@ -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;
}
}