Esempio n. 1
0
        static void Main(string[] args)
        {
            Controller xbox = new Controller(UserIndex.One);
            Console.WriteLine("Controller connected: " + xbox.IsConnected);
            BatteryInformation battery = xbox.GetBatteryInformation(BatteryDeviceType.Gamepad);
            Console.WriteLine("Battery level: " + battery.BatteryLevel);

            bool isRunning = true;

            while (isRunning)
            {
                Console.Clear();
                State state = xbox.GetState();

                switch (state.Gamepad.Buttons)
                {
                    case GamepadButtonFlags.Start:
                        isRunning = false;
                        break;
                    default:
                        break;
                }

                Console.Write("Key pressed: " + state.Gamepad.Buttons + "\n");
                Console.Write("RightThumbX stick: " + state.Gamepad.RightThumbX + "\n");
                Console.Write("RightThumbY stick: " + state.Gamepad.RightThumbY + "\n");
                Console.Write("LeftThumbX stick: " + state.Gamepad.LeftThumbX + "\n");
                Console.Write("LeftThumbY stick: " + state.Gamepad.LeftThumbY + "\n");
                Console.Write("LeftTrigger: " + state.Gamepad.LeftTrigger + "\n");
                Console.Write("RightTrigger: " + state.Gamepad.RightTrigger + "\n");

                int vibrationLeftMotorSpeed = 0;

                if (state.Gamepad.LeftThumbX > -1)
                    vibrationLeftMotorSpeed = state.Gamepad.LeftThumbX;

                vibration.LeftMotorSpeed = (ushort)vibrationLeftMotorSpeed;
                xbox.SetVibration(vibration);
                System.Threading.Thread.Sleep(100);
            }
        }
		uint XInputGetBatteryInformation_Hooked(int dwUserIndex, int devType, out BatteryInformation pBatteryInformation)
		{
			pBatteryInformation = new BatteryInformation();

			var controller = new Controller((UserIndex)dwUserIndex);
			if (controller.IsConnected)
			{
				try
				{
					pBatteryInformation = controller.GetBatteryInformation((BatteryDeviceType) devType);
				}
				catch
				{
					return ERROR_DEVICE_NOT_CONNECTED;
				}
			}
			else
			{
				pBatteryInformation.BatteryLevel = BatteryLevel.Full;
			}
			
			return ERROR_SUCCESS;
		}