//TODO: //make functions for IsAnyKeysPressed() and IsAllKeysPressed() //they should accept params of keys public bool GetKey(GameKeys KeyToFind, InputDeviceManagerAccess.ControllerIdType CurrControllerId) { bool RetVal = false; if (this._TypeOfDevice == InputDeviceAccess.TypeOfDevices.Keyboard) { foreach (DirectInput.Key a in this.PressedKeys) { if ((DirectInput.Key) this.KeyTable[CurrControllerId.DeviceUserId - 1][KeyToFind] == a) { RetVal = true; break; } } } else if (this._TypeOfDevice == InputDeviceAccess.TypeOfDevices.Gamepad) { byte[] ButtonStatus; int[] HatStatus; //Check hats and axis if (KeyToFind >= InputDeviceAccess.GameKeys.Up && KeyToFind <= InputDeviceAccess.GameKeys.Right) { HatStatus = this.device.CurrentJoystickState.GetPointOfView(); int PressedKeyValue = (int)(this.KeyTable[CurrControllerId.DeviceUserId - 1][KeyToFind]); switch (KeyToFind) { case (InputDeviceAccess.GameKeys.Up): if (HatStatus[0] == 0 || HatStatus[0] == 4500 || HatStatus[0] == 31500) { RetVal = true; } break; case (InputDeviceAccess.GameKeys.Left): if (HatStatus[0] == 27000 || HatStatus[0] == 31500 || HatStatus[0] == 22500) { RetVal = true; } break; case (InputDeviceAccess.GameKeys.Right): if (HatStatus[0] == 9000 || HatStatus[0] == 4500 || HatStatus[0] == 13500) { RetVal = true; } break; case (InputDeviceAccess.GameKeys.Down): if (HatStatus[0] == 18000 || HatStatus[0] == 22500 || HatStatus[0] == 13500) { RetVal = true; } break; } } //Check buttons else if (KeyToFind == InputDeviceAccess.GameKeys.Attack) { ButtonStatus = this.device.CurrentJoystickState.GetButtons(); int PressedKeyValue = (int)(this.KeyTable[CurrControllerId.DeviceUserId - 1][KeyToFind]); if (ButtonStatus[PressedKeyValue] > 0) { RetVal = true; } } } return(RetVal); }
public void SetInputDevices(InputDeviceManagerAccess NewParentInputDeviceManager, InputDeviceManagerAccess.ControllerIdType NewControllerId) { this.ParentInputDeviceManager = NewParentInputDeviceManager; this.ControllerId = NewControllerId; }