Some work on keyboard input. It is currently not working, see issue #449 for further information
This commit is contained in:
parent
2c30d8ff7e
commit
e02485ab9e
@ -70,7 +70,8 @@ namespace ANX.Framework
|
||||
this.game = game;
|
||||
//this.LockThreadToProcessor();
|
||||
this.gameWindow = new WindowsGameWindow();
|
||||
Mouse.WindowHandle = this.gameWindow.Handle;
|
||||
Mouse.WindowHandle = this.gameWindow.Handle; //TODO: find a way to initialize all InputSystems with one Handle
|
||||
Keyboard.WindowHandle = this.gameWindow.Handle;
|
||||
//TouchPanel.WindowHandle = this.gameWindow.Handle;
|
||||
//this.gameWindow.IsMouseVisible = game.IsMouseVisible;
|
||||
this.gameWindow.Activated += new EventHandler<EventArgs>(this.GameWindowActivated);
|
||||
|
@ -62,10 +62,26 @@ namespace ANX.Framework.Input
|
||||
keyboard = AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().Keyboard;
|
||||
}
|
||||
|
||||
internal static IntPtr WindowHandle
|
||||
{
|
||||
get
|
||||
{
|
||||
return keyboard != null ? keyboard.WindowHandle : IntPtr.Zero;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (keyboard != null)
|
||||
{
|
||||
keyboard.WindowHandle = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static KeyboardState GetState()
|
||||
{
|
||||
return keyboard.GetState();
|
||||
}
|
||||
|
||||
public static KeyboardState GetState (PlayerIndex playerIndex)
|
||||
{
|
||||
return keyboard.GetState(playerIndex);
|
||||
|
@ -77,7 +77,7 @@ namespace ANX.Framework.Input
|
||||
|
||||
public bool IsKeyDown(Keys key)
|
||||
{
|
||||
return keyState[(int)key] == KeyState.Down;
|
||||
return keyState != null ? keyState[(int)key] == KeyState.Down : false;
|
||||
}
|
||||
|
||||
public bool IsKeyUp(Keys key)
|
||||
|
@ -62,7 +62,7 @@ namespace ANX.Framework.Input
|
||||
mouse = AddInSystemFactory.Instance.GetDefaultCreator<IInputSystemCreator>().Mouse;
|
||||
}
|
||||
|
||||
public static IntPtr WindowHandle
|
||||
internal static IntPtr WindowHandle
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -6,8 +6,9 @@ using ANX.Framework.Input;
|
||||
|
||||
namespace ANX.Framework.NonXNA
|
||||
{
|
||||
public interface IKeyboard
|
||||
public interface IKeyboard : IDisposable
|
||||
{
|
||||
IntPtr WindowHandle { get; set; }
|
||||
KeyboardState GetState();
|
||||
KeyboardState GetState(PlayerIndex playerIndex);
|
||||
}
|
||||
|
@ -42,6 +42,7 @@
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
|
@ -60,7 +60,7 @@ namespace ANX.InputSystem.Windows.XInput
|
||||
{
|
||||
public class Creator : IInputSystemCreator
|
||||
{
|
||||
#region IInputSystemCreator Member
|
||||
|
||||
|
||||
public string Name
|
||||
{
|
||||
@ -94,9 +94,6 @@ namespace ANX.InputSystem.Windows.XInput
|
||||
{
|
||||
get { return new Keyboard(); }
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -56,6 +56,21 @@ namespace ANX.InputSystem.Windows.XInput
|
||||
{
|
||||
internal class FormatConverter
|
||||
{
|
||||
public static KeyboardState Translate(SharpDX.DirectInput.KeyboardState keyboardState)
|
||||
{
|
||||
int keyCount = keyboardState.PressedKeys.Count;
|
||||
Keys[] keys = new Keys[keyCount];
|
||||
|
||||
for (int i = 0; i < keyCount; i++)
|
||||
{
|
||||
keys[i] = (ANX.Framework.Input.Keys)((int)keyboardState.PressedKeys[i]);
|
||||
}
|
||||
|
||||
KeyboardState ks = new KeyboardState(keys);
|
||||
|
||||
return ks;
|
||||
}
|
||||
|
||||
public static Buttons Translate(SharpDX.XInput.GamepadButtonFlags buttons)
|
||||
{
|
||||
Buttons tb = 0;
|
||||
|
@ -55,19 +55,70 @@ using DXKeyboard=SharpDX.DirectInput.Keyboard;
|
||||
// particular purpose and non-infringement.
|
||||
|
||||
#endregion // License
|
||||
|
||||
namespace ANX.InputSystem.Windows.XInput
|
||||
{
|
||||
public class Keyboard:IKeyboard
|
||||
public class Keyboard : IKeyboard
|
||||
{
|
||||
private DXKeyboard keyboroard;
|
||||
#region Private Members
|
||||
private DirectInput directInput;
|
||||
private DXKeyboard nativeKeyboard;
|
||||
private KeyboardState nativeState;
|
||||
|
||||
#endregion // Private Members
|
||||
|
||||
public IntPtr WindowHandle
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public Keyboard()
|
||||
{
|
||||
this.nativeState = new KeyboardState();
|
||||
}
|
||||
|
||||
public Framework.Input.KeyboardState GetState()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return GetState(Framework.PlayerIndex.One);
|
||||
}
|
||||
|
||||
public Framework.Input.KeyboardState GetState(Framework.PlayerIndex playerIndex)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (this.nativeKeyboard == null && this.WindowHandle != null && this.WindowHandle != IntPtr.Zero)
|
||||
{
|
||||
this.directInput = new DirectInput();
|
||||
this.nativeKeyboard = new DXKeyboard(this.directInput);
|
||||
this.nativeKeyboard.SetCooperativeLevel(this.WindowHandle, CooperativeLevel.NonExclusive | CooperativeLevel.Background);
|
||||
this.nativeKeyboard.Acquire();
|
||||
}
|
||||
|
||||
if (this.nativeKeyboard != null)
|
||||
{
|
||||
nativeKeyboard.GetCurrentState(ref this.nativeState);
|
||||
if (this.nativeState.PressedKeys.Count > 0)
|
||||
{
|
||||
return FormatConverter.Translate(this.nativeState);
|
||||
}
|
||||
}
|
||||
|
||||
return new Framework.Input.KeyboardState();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (this.nativeKeyboard != null)
|
||||
{
|
||||
this.nativeKeyboard.Unacquire();
|
||||
this.nativeKeyboard.Dispose();
|
||||
this.nativeKeyboard = null;
|
||||
}
|
||||
|
||||
if (this.directInput != null)
|
||||
{
|
||||
this.directInput.Dispose();
|
||||
this.directInput = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ using MouseX = SharpDX.DirectInput.Mouse;
|
||||
|
||||
namespace ANX.InputSystem.Windows.XInput
|
||||
{
|
||||
class Mouse:IMouse
|
||||
class Mouse : IMouse
|
||||
{
|
||||
[DllImport("user32.dll")]
|
||||
static extern bool GetCursorPos(ref Point lpPoint);
|
||||
|
@ -109,7 +109,7 @@ namespace WindowsGame1
|
||||
protected override void Update(GameTime gameTime)
|
||||
{
|
||||
// Allows the game to exit
|
||||
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
|
||||
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
|
||||
{
|
||||
this.Exit();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user