From 4e6a14a9841667f19203d92067fc7f7f8259ba03 Mon Sep 17 00:00:00 2001 From: Glatzemann Date: Wed, 14 Dec 2011 19:54:23 +0000 Subject: [PATCH] re-added some missing files --- .../ANX.InputDevices.Windows.XInput.csproj | 94 ++++ .../FormatConverter.cs | 404 ++++++++++++++++++ .../GamePad.cs | 159 +++++++ .../GamePadCreator.cs | 88 ++++ .../Keyboard.cs | 128 ++++++ .../KeyboardCreator.cs | 88 ++++ .../Metadata.Designer.cs | 72 ++++ .../Metadata.resx | 124 ++++++ .../ANX.InputDevices.Windows.XInput/Mouse.cs | 137 ++++++ .../MouseCreator.cs | 88 ++++ 10 files changed, 1382 insertions(+) create mode 100644 InputSystems/ANX.InputDevices.Windows.XInput/ANX.InputDevices.Windows.XInput.csproj create mode 100644 InputSystems/ANX.InputDevices.Windows.XInput/FormatConverter.cs create mode 100644 InputSystems/ANX.InputDevices.Windows.XInput/GamePad.cs create mode 100644 InputSystems/ANX.InputDevices.Windows.XInput/GamePadCreator.cs create mode 100644 InputSystems/ANX.InputDevices.Windows.XInput/Keyboard.cs create mode 100644 InputSystems/ANX.InputDevices.Windows.XInput/KeyboardCreator.cs create mode 100644 InputSystems/ANX.InputDevices.Windows.XInput/Metadata.Designer.cs create mode 100644 InputSystems/ANX.InputDevices.Windows.XInput/Metadata.resx create mode 100644 InputSystems/ANX.InputDevices.Windows.XInput/Mouse.cs create mode 100644 InputSystems/ANX.InputDevices.Windows.XInput/MouseCreator.cs diff --git a/InputSystems/ANX.InputDevices.Windows.XInput/ANX.InputDevices.Windows.XInput.csproj b/InputSystems/ANX.InputDevices.Windows.XInput/ANX.InputDevices.Windows.XInput.csproj new file mode 100644 index 00000000..b4a750ec --- /dev/null +++ b/InputSystems/ANX.InputDevices.Windows.XInput/ANX.InputDevices.Windows.XInput.csproj @@ -0,0 +1,94 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {60D08399-244F-46A3-91F1-4CFD26D961A3} + Library + Properties + ANX.InputDevices.Windows.XInput + ANX.InputDevices.Windows.XInput + v4.0 + 512 + + + true + full + false + ..\..\bin\Debug\ + TRACE;DEBUG;XNAEXT + prompt + 4 + + + pdbonly + true + ..\..\bin\Debug\ + TRACE + prompt + 4 + + + + False + ..\..\lib\NLog\NLog.dll + + + ..\..\lib\SharpDX\Bin\SharpDX.dll + + + ..\..\lib\SharpDX\Bin\SharpDX.Diagnostics.dll + + + ..\..\lib\SharpDX\Bin\SharpDX.DirectInput.dll + + + ..\..\lib\SharpDX\Bin\SharpDX.XInput.dll + + + + + + + + + + + + + + + + + + Metadata.resx + True + True + + + + + + + + {6899F0C9-70B9-4EB0-9DD3-E598D4BE3E35} + ANX.Framework + + + + + PublicResXFileCodeGenerator + Metadata.Designer.cs + + + + + \ No newline at end of file diff --git a/InputSystems/ANX.InputDevices.Windows.XInput/FormatConverter.cs b/InputSystems/ANX.InputDevices.Windows.XInput/FormatConverter.cs new file mode 100644 index 00000000..990f3599 --- /dev/null +++ b/InputSystems/ANX.InputDevices.Windows.XInput/FormatConverter.cs @@ -0,0 +1,404 @@ +#region Using Statements +using System; +using ANX.Framework.Input; +using SharpDX.XInput; + +#endregion // Using Statements + +#region License + +// +// This file is part of the ANX.Framework created by the "ANX.Framework developer group". +// +// This file is released under the Ms-PL license. +// +// +// +// Microsoft Public License (Ms-PL) +// +// This license governs use of the accompanying software. If you use the software, you accept this license. +// If you do not accept the license, do not use the software. +// +// 1.Definitions +// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning +// here as under U.S. copyright law. +// A "contribution" is the original software, or any additions or changes to the software. +// A "contributor" is any person that distributes its contribution under this license. +// "Licensed patents" are a contributor's patent claims that read directly on its contribution. +// +// 2.Grant of Rights +// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations +// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to +// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution +// or any derivative works that you create. +// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in +// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed +// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution +// in the software or derivative works of the contribution in the software. +// +// 3.Conditions and Limitations +// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. +// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your +// patent license from such contributor to the software ends automatically. +// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution +// notices that are present in the software. +// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including +// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or +// object code form, you may only do so under a license that complies with this license. +// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees, +// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the +// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a +// particular purpose and non-infringement. + +#endregion // License + +namespace ANX.InputDevices.Windows.XInput +{ + internal class FormatConverter + { + public static ANX.Framework.Input.Keys Translate(SharpDX.DirectInput.Key key) + { + //TODO: implement all keys + //TODO: test if a array with the mapping which is constructed once is faster + + switch (key) + { + case SharpDX.DirectInput.Key.A: + return Keys.A; + case SharpDX.DirectInput.Key.AT: + break; + case SharpDX.DirectInput.Key.AX: + break; + case SharpDX.DirectInput.Key.AbntC1: + break; + case SharpDX.DirectInput.Key.AbntC2: + break; + case SharpDX.DirectInput.Key.Add: + return Keys.Add; + case SharpDX.DirectInput.Key.Apostrophe: + break; + case SharpDX.DirectInput.Key.Applications: + //check + return Keys.Apps; + case SharpDX.DirectInput.Key.B: + return Keys.B; + case SharpDX.DirectInput.Key.Back: + return Keys.Back; + case SharpDX.DirectInput.Key.Backslash: + return Keys.OemBackslash; + case SharpDX.DirectInput.Key.C: + return Keys.C; + case SharpDX.DirectInput.Key.Calculator: + break; + case SharpDX.DirectInput.Key.Capital: + //check + return Keys.CapsLock; + case SharpDX.DirectInput.Key.Colon: + break; + case SharpDX.DirectInput.Key.Comma: + return Keys.OemComma; + case SharpDX.DirectInput.Key.Convert: + return Keys.ImeConvert; + case SharpDX.DirectInput.Key.D: + return Keys.D; + case SharpDX.DirectInput.Key.D0: + return Keys.D0; + case SharpDX.DirectInput.Key.D1: + return Keys.D1; + case SharpDX.DirectInput.Key.D2: + return Keys.D2; + case SharpDX.DirectInput.Key.D3: + return Keys.D3; + case SharpDX.DirectInput.Key.D4: + return Keys.D4; + case SharpDX.DirectInput.Key.D5: + return Keys.D5; + case SharpDX.DirectInput.Key.D6: + return Keys.D6; + case SharpDX.DirectInput.Key.D7: + return Keys.D7; + case SharpDX.DirectInput.Key.D8: + return Keys.D8; + case SharpDX.DirectInput.Key.D9: + return Keys.D9; + case SharpDX.DirectInput.Key.Decimal: + return Keys.Decimal; + case SharpDX.DirectInput.Key.Delete: + return Keys.Delete; + case SharpDX.DirectInput.Key.Divide: + return Keys.Divide; + case SharpDX.DirectInput.Key.Down: + return Keys.Down; + case SharpDX.DirectInput.Key.E: + return Keys.E; + case SharpDX.DirectInput.Key.End: + return Keys.End; + case SharpDX.DirectInput.Key.Equals: + break; + case SharpDX.DirectInput.Key.Escape: + return Keys.Escape; + case SharpDX.DirectInput.Key.F: + return Keys.F; + case SharpDX.DirectInput.Key.F1: + return Keys.F1; + case SharpDX.DirectInput.Key.F10: + return Keys.F10; + case SharpDX.DirectInput.Key.F11: + return Keys.F11; + case SharpDX.DirectInput.Key.F12: + return Keys.F12; + case SharpDX.DirectInput.Key.F13: + return Keys.F13; + case SharpDX.DirectInput.Key.F14: + return Keys.F14; + case SharpDX.DirectInput.Key.F15: + return Keys.F15; + case SharpDX.DirectInput.Key.F2: + return Keys.F2; + case SharpDX.DirectInput.Key.F3: + return Keys.F3; + case SharpDX.DirectInput.Key.F4: + return Keys.F4; + case SharpDX.DirectInput.Key.F5: + return Keys.F5; + case SharpDX.DirectInput.Key.F6: + return Keys.F6; + case SharpDX.DirectInput.Key.F7: + return Keys.F7; + case SharpDX.DirectInput.Key.F8: + return Keys.F8; + case SharpDX.DirectInput.Key.F9: + return Keys.F9; + case SharpDX.DirectInput.Key.G: + return Keys.G; + case SharpDX.DirectInput.Key.Grave: + break; + case SharpDX.DirectInput.Key.H: + return Keys.H; + case SharpDX.DirectInput.Key.Home: + return Keys.Home; + case SharpDX.DirectInput.Key.I: + return Keys.I; + case SharpDX.DirectInput.Key.Insert: + return Keys.Insert; + case SharpDX.DirectInput.Key.J: + return Keys.J; + case SharpDX.DirectInput.Key.K: + return Keys.K; + case SharpDX.DirectInput.Key.Kana: + return Keys.Kana; + case SharpDX.DirectInput.Key.Kanji: + return Keys.Kanji; + case SharpDX.DirectInput.Key.L: + return Keys.L; + case SharpDX.DirectInput.Key.Left: + return Keys.Left; + case SharpDX.DirectInput.Key.LeftAlt: + return Keys.LeftAlt; + case SharpDX.DirectInput.Key.LeftBracket: + return Keys.OemOpenBrackets; + case SharpDX.DirectInput.Key.LeftControl: + return Keys.LeftControl; + case SharpDX.DirectInput.Key.LeftShift: + return Keys.LeftShift; + case SharpDX.DirectInput.Key.LeftWindowsKey: + return Keys.LeftWindows; + case SharpDX.DirectInput.Key.M: + return Keys.M; + case SharpDX.DirectInput.Key.Mail: + return Keys.LaunchMail; + case SharpDX.DirectInput.Key.MediaSelect: + return Keys.SelectMedia; + case SharpDX.DirectInput.Key.MediaStop: + return Keys.MediaStop; + case SharpDX.DirectInput.Key.Minus: + break; + case SharpDX.DirectInput.Key.Multiply: + return Keys.Multiply; + case SharpDX.DirectInput.Key.Mute: + return Keys.VolumeMute; + case SharpDX.DirectInput.Key.MyComputer: + break; + case SharpDX.DirectInput.Key.N: + return Keys.N; + case SharpDX.DirectInput.Key.NextTrack: + return Keys.MediaNextTrack; + case SharpDX.DirectInput.Key.NoConvert: + return Keys.ImeNoConvert; + case SharpDX.DirectInput.Key.NumberLock: + return Keys.NumLock; + case SharpDX.DirectInput.Key.NumberPad0: + return Keys.NumPad0; + case SharpDX.DirectInput.Key.NumberPad1: + return Keys.NumPad1; + case SharpDX.DirectInput.Key.NumberPad2: + return Keys.NumPad2; + case SharpDX.DirectInput.Key.NumberPad3: + return Keys.NumPad3; + case SharpDX.DirectInput.Key.NumberPad4: + return Keys.NumPad4; + case SharpDX.DirectInput.Key.NumberPad5: + return Keys.NumPad5; + case SharpDX.DirectInput.Key.NumberPad6: + return Keys.NumPad6;; + case SharpDX.DirectInput.Key.NumberPad7: + return Keys.NumPad7; + case SharpDX.DirectInput.Key.NumberPad8: + return Keys.NumPad8; + case SharpDX.DirectInput.Key.NumberPad9: + return Keys.NumPad9; + case SharpDX.DirectInput.Key.NumberPadComma: + return Keys.OemComma; + case SharpDX.DirectInput.Key.NumberPadEnter: + return Keys.Enter; + case SharpDX.DirectInput.Key.NumberPadEquals: + break; + case SharpDX.DirectInput.Key.O: + return Keys.O; + case SharpDX.DirectInput.Key.Oem102: + break; + case SharpDX.DirectInput.Key.P: + return Keys.P; + case SharpDX.DirectInput.Key.PageDown: + return Keys.PageDown; + case SharpDX.DirectInput.Key.PageUp: + return Keys.PageUp; + case SharpDX.DirectInput.Key.Pause: + return Keys.Pause; + case SharpDX.DirectInput.Key.Period: + return Keys.OemPeriod; + case SharpDX.DirectInput.Key.PlayPause: + return Keys.MediaPlayPause; + case SharpDX.DirectInput.Key.Power: + break; + case SharpDX.DirectInput.Key.PreviousTrack: + return Keys.MediaPreviousTrack; + case SharpDX.DirectInput.Key.PrintScreen: + return Keys.PrintScreen; + case SharpDX.DirectInput.Key.Q: + return Keys.Q; + case SharpDX.DirectInput.Key.R: + return Keys.R; + case SharpDX.DirectInput.Key.Return: + //check + return Keys.Enter; + case SharpDX.DirectInput.Key.Right: + return Keys.Right; + case SharpDX.DirectInput.Key.RightAlt: + return Keys.RightAlt; + case SharpDX.DirectInput.Key.RightBracket: + return Keys.OemCloseBrackets; + case SharpDX.DirectInput.Key.RightControl: + return Keys.RightControl; + case SharpDX.DirectInput.Key.RightShift: + return Keys.RightShift; + case SharpDX.DirectInput.Key.RightWindowsKey: + return Keys.RightWindows; + case SharpDX.DirectInput.Key.S: + return Keys.S; + case SharpDX.DirectInput.Key.ScrollLock: + //check + return Keys.Scroll; + case SharpDX.DirectInput.Key.Semicolon: + return Keys.OemSemicolon; + case SharpDX.DirectInput.Key.Slash: + break; + case SharpDX.DirectInput.Key.Sleep: + return Keys.Sleep; + case SharpDX.DirectInput.Key.Space: + return Keys.Space; + case SharpDX.DirectInput.Key.Stop: + break; + case SharpDX.DirectInput.Key.Subtract: + return Keys.Subtract; + case SharpDX.DirectInput.Key.T: + return Keys.T; + case SharpDX.DirectInput.Key.Tab: + return Keys.Tab; + case SharpDX.DirectInput.Key.U: + return Keys.U; + case SharpDX.DirectInput.Key.Underline: + break; + case SharpDX.DirectInput.Key.Unknown: + break; + case SharpDX.DirectInput.Key.Unlabeled: + break; + case SharpDX.DirectInput.Key.UpArrow: + return Keys.Up; + case SharpDX.DirectInput.Key.V: + return Keys.V; + case SharpDX.DirectInput.Key.VolumeDown: + return Keys.VolumeDown; + case SharpDX.DirectInput.Key.VolumeUp: + return Keys.VolumeUp; + case SharpDX.DirectInput.Key.W: + return Keys.W; + case SharpDX.DirectInput.Key.Wake: + break; + case SharpDX.DirectInput.Key.WebBack: + return Keys.BrowserBack; + case SharpDX.DirectInput.Key.WebFavorites: + return Keys.BrowserFavorites; + case SharpDX.DirectInput.Key.WebForward: + return Keys.BrowserForward; + case SharpDX.DirectInput.Key.WebHome: + return Keys.BrowserHome; + case SharpDX.DirectInput.Key.WebRefresh: + return Keys.BrowserRefresh; + case SharpDX.DirectInput.Key.WebSearch: + return Keys.BrowserSearch; + case SharpDX.DirectInput.Key.WebStop: + return Keys.BrowserStop; + case SharpDX.DirectInput.Key.X: + return Keys.X; + case SharpDX.DirectInput.Key.Y: + return Keys.Y; + case SharpDX.DirectInput.Key.Yen: + break; + case SharpDX.DirectInput.Key.Z: + return Keys.Z; + default: + break; + } + + throw new NotImplementedException(); + } + + 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] = Translate(keyboardState.PressedKeys[i]); + } + + KeyboardState ks = new KeyboardState(keys); + + return ks; + } + + public static Buttons Translate(SharpDX.XInput.GamepadButtonFlags buttons) + { + Buttons tb = 0; + + tb |= (buttons & GamepadButtonFlags.A) == GamepadButtonFlags.A ? Buttons.A : 0; + tb |= (buttons & GamepadButtonFlags.B) == GamepadButtonFlags.B ? Buttons.B : 0; + tb |= (buttons & GamepadButtonFlags.Back) == GamepadButtonFlags.Back ? Buttons.Back : 0; + tb |= (buttons & GamepadButtonFlags.DPadDown) == GamepadButtonFlags.DPadDown ? Buttons.DPadDown : 0; + tb |= (buttons & GamepadButtonFlags.DPadLeft) == GamepadButtonFlags.DPadLeft ? Buttons.DPadLeft : 0; + tb |= (buttons & GamepadButtonFlags.DPadRight) == GamepadButtonFlags.DPadRight ? Buttons.DPadRight : 0; + tb |= (buttons & GamepadButtonFlags.DPadUp) == GamepadButtonFlags.DPadUp ? Buttons.DPadUp : 0; + tb |= (buttons & GamepadButtonFlags.LeftShoulder) == GamepadButtonFlags.LeftShoulder ? Buttons.LeftShoulder : 0; + tb |= (buttons & GamepadButtonFlags.LeftThumb) == GamepadButtonFlags.LeftThumb ? Buttons.LeftTrigger : 0; + tb |= (buttons & GamepadButtonFlags.RightShoulder) == GamepadButtonFlags.RightShoulder ? Buttons.RightShoulder : 0; + tb |= (buttons & GamepadButtonFlags.RightThumb) == GamepadButtonFlags.RightThumb ? Buttons.RightTrigger : 0; + tb |= (buttons & GamepadButtonFlags.Start) == GamepadButtonFlags.Start ? Buttons.Start : 0; + tb |= (buttons & GamepadButtonFlags.X) == GamepadButtonFlags.X ? Buttons.X : 0; + tb |= (buttons & GamepadButtonFlags.Y) == GamepadButtonFlags.Y ? Buttons.Y : 0; + + return tb; + } + } +} diff --git a/InputSystems/ANX.InputDevices.Windows.XInput/GamePad.cs b/InputSystems/ANX.InputDevices.Windows.XInput/GamePad.cs new file mode 100644 index 00000000..22426b73 --- /dev/null +++ b/InputSystems/ANX.InputDevices.Windows.XInput/GamePad.cs @@ -0,0 +1,159 @@ +#region Using Statements +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; +using System.Runtime.InteropServices; +using ANX.Framework.NonXNA; +using ANX.Framework.Input; +using ANX.Framework; +using SharpDX.XInput; + +#endregion // Using Statements + +#region License + +// +// This file is part of the ANX.Framework created by the "ANX.Framework developer group". +// +// This file is released under the Ms-PL license. +// +// +// +// Microsoft Public License (Ms-PL) +// +// This license governs use of the accompanying software. If you use the software, you accept this license. +// If you do not accept the license, do not use the software. +// +// 1.Definitions +// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning +// here as under U.S. copyright law. +// A "contribution" is the original software, or any additions or changes to the software. +// A "contributor" is any person that distributes its contribution under this license. +// "Licensed patents" are a contributor's patent claims that read directly on its contribution. +// +// 2.Grant of Rights +// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations +// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to +// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution +// or any derivative works that you create. +// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in +// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed +// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution +// in the software or derivative works of the contribution in the software. +// +// 3.Conditions and Limitations +// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. +// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your +// patent license from such contributor to the software ends automatically. +// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution +// notices that are present in the software. +// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including +// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or +// object code form, you may only do so under a license that complies with this license. +// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees, +// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the +// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a +// particular purpose and non-infringement. + +#endregion // License + +namespace ANX.InputDevices.Windows.XInput +{ + public class GamePad : IGamePad + { + #region Private Members + private Controller[] controller; + private const float thumbstickRangeFactor = 1.0f / short.MaxValue; + + #endregion // Private Members + + public GamePad() + { + controller = new Controller[4]; + controller[0] = new Controller(UserIndex.One); + controller[1] = new Controller(UserIndex.Two); + controller[2] = new Controller(UserIndex.Three); + controller[3] = new Controller(UserIndex.Four); + } + public GamePadCapabilities GetCapabilities(PlayerIndex playerIndex) + { + Capabilities result; + GamePadCapabilities returnres; + //SharpDX.XInput.Capabilities = new SharpDX.XInput.Capabilities(); + try + { + result = controller[(int)playerIndex].GetCapabilities(DeviceQueryType.Gamepad); + returnres = new GamePadCapabilities(); + + } + catch (Exception) + { + + returnres = new GamePadCapabilities(); + } return returnres; + } + + public GamePadState GetState(PlayerIndex playerIndex, out bool isConnected, out int packetNumber) + { + State result; + GamePadState returnres; + if(controller[(int)playerIndex].IsConnected) + { + result = controller[(int)playerIndex].GetState(); + //returnres = new GamePadCapabilities(result.Type,result.Gamepad.Buttons.) + returnres = new GamePadState(new Vector2(result.Gamepad.LeftThumbX * thumbstickRangeFactor, result.Gamepad.LeftThumbY * thumbstickRangeFactor), new Vector2(result.Gamepad.RightThumbX * thumbstickRangeFactor, result.Gamepad.RightThumbY * thumbstickRangeFactor), (float)result.Gamepad.LeftTrigger, (float)result.Gamepad.RightTrigger, FormatConverter.Translate(result.Gamepad.Buttons)); + packetNumber = result.PacketNumber; + isConnected = true; + } + else + { + isConnected = false; + packetNumber = 0; + returnres = new GamePadState(); + } + + + return returnres; + } + + public GamePadState GetState(PlayerIndex playerIndex, GamePadDeadZone deadZoneMode, out bool isConnected, out int packetNumber) + { + throw new NotImplementedException(); + } + + public bool SetVibration(PlayerIndex playerIndex, float leftMotor, float rightMotor) + { + short left; + short right; + if (Math.Abs(leftMotor)>1) + { + left = 1; + } + else + { + left = Convert.ToInt16(Math.Abs(leftMotor) * short.MaxValue); + } + if (Math.Abs(rightMotor) > 1) + { + right = 1; + } + else + { + right = Convert.ToInt16(Math.Abs(rightMotor) * short.MaxValue); + } + + if (controller[(int)playerIndex].IsConnected) + { + Vibration vib = new Vibration(); + vib.LeftMotorSpeed = left; + vib.RightMotorSpeed = right; + controller[(int)playerIndex].SetVibration(vib); + return true; + } + return false; + + } + } +} diff --git a/InputSystems/ANX.InputDevices.Windows.XInput/GamePadCreator.cs b/InputSystems/ANX.InputDevices.Windows.XInput/GamePadCreator.cs new file mode 100644 index 00000000..d0da88b8 --- /dev/null +++ b/InputSystems/ANX.InputDevices.Windows.XInput/GamePadCreator.cs @@ -0,0 +1,88 @@ +#region Using Statements +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; +using System.Runtime.InteropServices; +using ANX.Framework.NonXNA; +using NLog; +using ANX.Framework.NonXNA.InputSystem; + +#endregion // Using Statements + +#region License + +// +// This file is part of the ANX.Framework created by the "ANX.Framework developer group". +// +// This file is released under the Ms-PL license. +// +// +// +// Microsoft Public License (Ms-PL) +// +// This license governs use of the accompanying software. If you use the software, you accept this license. +// If you do not accept the license, do not use the software. +// +// 1.Definitions +// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning +// here as under U.S. copyright law. +// A "contribution" is the original software, or any additions or changes to the software. +// A "contributor" is any person that distributes its contribution under this license. +// "Licensed patents" are a contributor's patent claims that read directly on its contribution. +// +// 2.Grant of Rights +// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations +// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to +// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution +// or any derivative works that you create. +// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in +// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed +// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution +// in the software or derivative works of the contribution in the software. +// +// 3.Conditions and Limitations +// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. +// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your +// patent license from such contributor to the software ends automatically. +// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution +// notices that are present in the software. +// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including +// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or +// object code form, you may only do so under a license that complies with this license. +// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees, +// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the +// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a +// particular purpose and non-infringement. + +#endregion // License + +namespace ANX.InputDevices.Windows.XInput +{ + public class GamePadCreator : IGamePadCreator + { + public string Name + { + get + { + return "XInput.GamePad"; + } + } + + public void RegisterCreator(InputDeviceFactory factory) + { + factory.AddCreator(this); + } + + public int Priority + { + get { return 10; } + } + + public IGamePad CreateGamePadInstance() + { + return new GamePad(); + } + } +} diff --git a/InputSystems/ANX.InputDevices.Windows.XInput/Keyboard.cs b/InputSystems/ANX.InputDevices.Windows.XInput/Keyboard.cs new file mode 100644 index 00000000..4f0a1da2 --- /dev/null +++ b/InputSystems/ANX.InputDevices.Windows.XInput/Keyboard.cs @@ -0,0 +1,128 @@ +#region Using Statements +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using ANX.InputDevices; +using ANX.Framework.NonXNA; +using SharpDX.DirectInput; +using DXKeyboard=SharpDX.DirectInput.Keyboard; +#endregion // Using Statements + +#region License + +// +// This file is part of the ANX.Framework created by the "ANX.Framework developer group". +// +// This file is released under the Ms-PL license. +// +// +// +// Microsoft Public License (Ms-PL) +// +// This license governs use of the accompanying software. If you use the software, you accept this license. +// If you do not accept the license, do not use the software. +// +// 1.Definitions +// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning +// here as under U.S. copyright law. +// A "contribution" is the original software, or any additions or changes to the software. +// A "contributor" is any person that distributes its contribution under this license. +// "Licensed patents" are a contributor's patent claims that read directly on its contribution. +// +// 2.Grant of Rights +// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations +// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to +// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution +// or any derivative works that you create. +// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in +// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed +// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution +// in the software or derivative works of the contribution in the software. +// +// 3.Conditions and Limitations +// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. +// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your +// patent license from such contributor to the software ends automatically. +// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution +// notices that are present in the software. +// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including +// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or +// object code form, you may only do so under a license that complies with this license. +// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees, +// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the +// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a +// particular purpose and non-infringement. + +#endregion // License + +namespace ANX.InputDevices.Windows.XInput +{ + public class Keyboard : IKeyboard + { + #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(Framework.PlayerIndex playerIndex) + { + //TODO: prevent new + + // only available on XBox, behaviour regarding MSDN: empty keystate + + return new Framework.Input.KeyboardState(); + } + + public Framework.Input.KeyboardState GetState() + { + 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; + } + } + } +} diff --git a/InputSystems/ANX.InputDevices.Windows.XInput/KeyboardCreator.cs b/InputSystems/ANX.InputDevices.Windows.XInput/KeyboardCreator.cs new file mode 100644 index 00000000..0d1d26bf --- /dev/null +++ b/InputSystems/ANX.InputDevices.Windows.XInput/KeyboardCreator.cs @@ -0,0 +1,88 @@ +#region Using Statements +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; +using System.Runtime.InteropServices; +using ANX.Framework.NonXNA; +using NLog; +using ANX.Framework.NonXNA.InputSystem; + +#endregion // Using Statements + +#region License + +// +// This file is part of the ANX.Framework created by the "ANX.Framework developer group". +// +// This file is released under the Ms-PL license. +// +// +// +// Microsoft Public License (Ms-PL) +// +// This license governs use of the accompanying software. If you use the software, you accept this license. +// If you do not accept the license, do not use the software. +// +// 1.Definitions +// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning +// here as under U.S. copyright law. +// A "contribution" is the original software, or any additions or changes to the software. +// A "contributor" is any person that distributes its contribution under this license. +// "Licensed patents" are a contributor's patent claims that read directly on its contribution. +// +// 2.Grant of Rights +// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations +// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to +// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution +// or any derivative works that you create. +// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in +// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed +// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution +// in the software or derivative works of the contribution in the software. +// +// 3.Conditions and Limitations +// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. +// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your +// patent license from such contributor to the software ends automatically. +// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution +// notices that are present in the software. +// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including +// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or +// object code form, you may only do so under a license that complies with this license. +// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees, +// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the +// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a +// particular purpose and non-infringement. + +#endregion // License + +namespace ANX.InputDevices.Windows.XInput +{ + public class KeyboardCreator : IKeyboardCreator + { + public string Name + { + get + { + return "DirectInput.DXKeyboard"; + } + } + + public void RegisterCreator(InputDeviceFactory factory) + { + factory.AddCreator(this); + } + + public int Priority + { + get { return 10; } + } + + public IKeyboard CreateKeyboardInstance() + { + return new Keyboard(); + } + } +} diff --git a/InputSystems/ANX.InputDevices.Windows.XInput/Metadata.Designer.cs b/InputSystems/ANX.InputDevices.Windows.XInput/Metadata.Designer.cs new file mode 100644 index 00000000..7488ddfe --- /dev/null +++ b/InputSystems/ANX.InputDevices.Windows.XInput/Metadata.Designer.cs @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// +// Dieser Code wurde von einem Tool generiert. +// Laufzeitversion: 4.0.30319.239 +// +// Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn +// der Code erneut generiert wird. +// +//------------------------------------------------------------------------------ + +namespace ANX.InputDevices.Windows.XInput { + using System; + + + /// + /// Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw. + /// + // Diese Klasse wurde von der StronglyTypedResourceBuilder automatisch generiert + // -Klasse über ein Tool wie ResGen oder Visual Studio automatisch generiert. + // Um einen Member hinzuzufügen oder zu entfernen, bearbeiten Sie die .ResX-Datei und führen dann ResGen + // mit der /str-Option erneut aus, oder Sie erstellen Ihr VS-Projekt neu. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class Metadata { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Metadata() { + } + + /// + /// Gibt die zwischengespeicherte ResourceManager-Instanz zurück, die von dieser Klasse verwendet wird. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ANX.InputDevices.Windows.XInput.Metadata", typeof(Metadata).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Überschreibt die CurrentUICulture-Eigenschaft des aktuellen Threads für alle + /// Ressourcenzuordnungen, die diese stark typisierte Ressourcenklasse verwenden. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Sucht eine lokalisierte Zeichenfolge, die Win32NT ähnelt. + /// + public static string SupportedPlatforms { + get { + return ResourceManager.GetString("SupportedPlatforms", resourceCulture); + } + } + } +} diff --git a/InputSystems/ANX.InputDevices.Windows.XInput/Metadata.resx b/InputSystems/ANX.InputDevices.Windows.XInput/Metadata.resx new file mode 100644 index 00000000..360b57fa --- /dev/null +++ b/InputSystems/ANX.InputDevices.Windows.XInput/Metadata.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Win32NT + + + \ No newline at end of file diff --git a/InputSystems/ANX.InputDevices.Windows.XInput/Mouse.cs b/InputSystems/ANX.InputDevices.Windows.XInput/Mouse.cs new file mode 100644 index 00000000..ed256615 --- /dev/null +++ b/InputSystems/ANX.InputDevices.Windows.XInput/Mouse.cs @@ -0,0 +1,137 @@ +#region Using Statements +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using ANX.Framework.NonXNA; +using ANX.Framework.Input; +using SharpDX.DirectInput; +using System.Runtime.InteropServices; +using ANX.Framework; + +#endregion // Using Statements + +#region License + +// +// This file is part of the ANX.Framework created by the "ANX.Framework developer group". +// +// This file is released under the Ms-PL license. +// +// +// +// Microsoft Public License (Ms-PL) +// +// This license governs use of the accompanying software. If you use the software, you accept this license. +// If you do not accept the license, do not use the software. +// +// 1.Definitions +// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning +// here as under U.S. copyright law. +// A "contribution" is the original software, or any additions or changes to the software. +// A "contributor" is any person that distributes its contribution under this license. +// "Licensed patents" are a contributor's patent claims that read directly on its contribution. +// +// 2.Grant of Rights +// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations +// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to +// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution +// or any derivative works that you create. +// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in +// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed +// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution +// in the software or derivative works of the contribution in the software. +// +// 3.Conditions and Limitations +// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. +// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your +// patent license from such contributor to the software ends automatically. +// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution +// notices that are present in the software. +// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including +// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or +// object code form, you may only do so under a license that complies with this license. +// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees, +// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the +// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a +// particular purpose and non-infringement. + +#endregion // License + +using MouseX = SharpDX.DirectInput.Mouse; + +namespace ANX.InputDevices.Windows.XInput +{ + class Mouse : IMouse + { + #region Interop + [DllImport("user32.dll")] + static extern bool GetCursorPos(ref Point lpPoint); + + [DllImport("user32.dll")] + static extern void SetCursorPos(int x, int y); + + [DllImport("user32.dll")] + static extern bool ScreenToClient(IntPtr hWnd, ref Point lpPoint); + + #endregion // Interop + + #region Private Members + private DirectInput directInput; + private MouseX mouse; + + #endregion // Private Members + + public IntPtr WindowHandle + { + get; + set; + } + + public Mouse() + { + this.directInput = new DirectInput(); + this.mouse = new MouseX(this.directInput); + this.mouse.Properties.AxisMode = DeviceAxisMode.Absolute; + this.mouse.Acquire(); + } + + public ANX.Framework.Input.MouseState GetState() + { + var state = this.mouse.GetCurrentState(); + + Point cursorPos = new Point(); + GetCursorPos(ref cursorPos); + if (WindowHandle != IntPtr.Zero) + { + ScreenToClient(WindowHandle, ref cursorPos); + } + + state.X = cursorPos.X; + state.Y = cursorPos.Y; + + ButtonState left = new ButtonState(); + ButtonState middle = new ButtonState(); + ButtonState right = new ButtonState(); + ButtonState x1 = new ButtonState(); + ButtonState x2 = new ButtonState(); + if(state.Buttons[0]){left=ButtonState.Pressed;} + if(state.Buttons[1]){middle=ButtonState.Pressed;} + if(state.Buttons[2]){right=ButtonState.Pressed;} + if(state.Buttons[3]){x1=ButtonState.Pressed;} + if(state.Buttons[4]){x2=ButtonState.Pressed;} + return new ANX.Framework.Input.MouseState(state.X,state.Y,state.Z,left,middle,right,x1,x2); + } + + public void SetPosition(int x, int y) + { + Point currentPosition = new Point(x, y); + GetCursorPos(ref currentPosition); + if (WindowHandle != IntPtr.Zero) + { + ScreenToClient(WindowHandle, ref currentPosition); + } + SetCursorPos(currentPosition.X, currentPosition.Y); + } + } +} diff --git a/InputSystems/ANX.InputDevices.Windows.XInput/MouseCreator.cs b/InputSystems/ANX.InputDevices.Windows.XInput/MouseCreator.cs new file mode 100644 index 00000000..1061cd00 --- /dev/null +++ b/InputSystems/ANX.InputDevices.Windows.XInput/MouseCreator.cs @@ -0,0 +1,88 @@ +#region Using Statements +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; +using System.Runtime.InteropServices; +using ANX.Framework.NonXNA; +using NLog; +using ANX.Framework.NonXNA.InputSystem; + +#endregion // Using Statements + +#region License + +// +// This file is part of the ANX.Framework created by the "ANX.Framework developer group". +// +// This file is released under the Ms-PL license. +// +// +// +// Microsoft Public License (Ms-PL) +// +// This license governs use of the accompanying software. If you use the software, you accept this license. +// If you do not accept the license, do not use the software. +// +// 1.Definitions +// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning +// here as under U.S. copyright law. +// A "contribution" is the original software, or any additions or changes to the software. +// A "contributor" is any person that distributes its contribution under this license. +// "Licensed patents" are a contributor's patent claims that read directly on its contribution. +// +// 2.Grant of Rights +// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations +// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to +// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution +// or any derivative works that you create. +// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in +// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed +// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution +// in the software or derivative works of the contribution in the software. +// +// 3.Conditions and Limitations +// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. +// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your +// patent license from such contributor to the software ends automatically. +// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution +// notices that are present in the software. +// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including +// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or +// object code form, you may only do so under a license that complies with this license. +// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees, +// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the +// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a +// particular purpose and non-infringement. + +#endregion // License + +namespace ANX.InputDevices.Windows.XInput +{ + public class MouseCreator : IMouseCreator + { + public string Name + { + get + { + return "DirectInput.Mouse"; + } + } + + public void RegisterCreator(InputDeviceFactory factory) + { + factory.AddCreator(this); + } + + public int Priority + { + get { return 10; } + } + + public IMouse CreateMouseInstance() + { + return new Mouse(); + } + } +}