private void PollKeyboardForAssignment() { int num = 0; ControllerPollingInfo pollingInfo = default(ControllerPollingInfo); ControllerPollingInfo pollingInfo2 = default(ControllerPollingInfo); ModifierKeyFlags modifierKeyFlags = ModifierKeyFlags.None; foreach (ControllerPollingInfo controllerPollingInfo in ReInput.controllers.Keyboard.PollForAllKeys()) { KeyCode keyboardKey = controllerPollingInfo.keyboardKey; if (keyboardKey != KeyCode.AltGr) { if (Keyboard.IsModifierKey(controllerPollingInfo.keyboardKey)) { if (num == 0) { pollingInfo2 = controllerPollingInfo; } modifierKeyFlags |= Keyboard.KeyCodeToModifierKeyFlags(keyboardKey); num++; } else if (pollingInfo.keyboardKey == KeyCode.None) { pollingInfo = controllerPollingInfo; } } } if (pollingInfo.keyboardKey == KeyCode.None) { if (num > 0 && num == 1) { if (ReInput.controllers.Keyboard.GetKeyTimePressed(pollingInfo2.keyboardKey) > 1f) { this._entry.pollingInfo = pollingInfo2; this._entry.controllerId = 0; this._entry.controllerType = ControllerType.Keyboard; this._entry.controllerMap = Input.player.controllers.maps.GetMap(ControllerType.Keyboard, 0, 0, 1); this.CheckMappingConflictAndConfirm(); return; } } return; } if (num == 0) { this._entry.pollingInfo = pollingInfo; this._entry.controllerId = 0; this._entry.controllerType = ControllerType.Keyboard; this._entry.controllerMap = Input.player.controllers.maps.GetMap(ControllerType.Keyboard, 0, 0, 1); this.CheckMappingConflictAndConfirm(); return; } this._entry.pollingInfo = pollingInfo; this._entry.modifierKeyFlags = modifierKeyFlags; this._entry.controllerId = 0; this._entry.controllerType = ControllerType.Keyboard; this._entry.controllerMap = Input.player.controllers.maps.GetMap(ControllerType.Keyboard, 0, 0, 1); this.CheckMappingConflictAndConfirm(); }
private ElementAssignment ToElementAssignment( ControllerPollingInfo _pollingInfo, ModifierKeyFlags _modifierKeyFlag, AxisRange _axisRange, int _actionId, ActionElementMap _actionElementMap) { AxisRange axisRange = (AxisRange)1; if (((ControllerPollingInfo) ref _pollingInfo).get_elementType() == null) { axisRange = _axisRange != null ? (((ControllerPollingInfo) ref _pollingInfo).get_axisPole() != null ? (AxisRange)2 : (AxisRange)1) : (AxisRange)0; } return(new ElementAssignment(((ControllerPollingInfo) ref _pollingInfo).get_controllerType(), ((ControllerPollingInfo) ref _pollingInfo).get_elementType(), ((ControllerPollingInfo) ref _pollingInfo).get_elementIdentifierId(), axisRange, ((ControllerPollingInfo) ref _pollingInfo).get_keyboardKey(), _modifierKeyFlag, _actionId, _axisRange != 2 ? (Pole)0 : (Pole)1, false, _actionElementMap == null ? -1 : _actionElementMap.get_id())); }
// Gets the axis direction and returns a suffix for that direction private string SGetAxisDir(ControllerPollingInfo info) { if (info.elementType == ControllerElementType.Axis) { if (aElementMaps[currentUIInputRow.PrimaryActionID].axisRange != AxisRange.Full) { if (info.axisPole == Pole.Positive) { return(" +"); } else if (info.axisPole == Pole.Negative) { return(" -"); } } } return(""); }
private void UpdateInputCheckMode() { ControllerPollingInfo _pollingInfo = ((ReInput.ControllerHelper.PollingHelper)ReInput.get_controllers().polling).PollControllerForFirstElementDown(this.selectedControllerType, this.selectedControllerId); if (!((ControllerPollingInfo) ref _pollingInfo).get_success() || ((ControllerPollingInfo) ref _pollingInfo).get_elementType() != 1) { return; } InputAction action = this.row.action; ActionElementMap _actionElementMap = !this.controllerMap.ContainsAction(action.get_id()) ? (ActionElementMap)null : this.controllerMap.GetElementMapsWithAction(action.get_id())[0]; ElementAssignment elementAssignment = this.ToElementAssignment(_pollingInfo, (ModifierKeyFlags)0, this.row.actionRange, action.get_id(), _actionElementMap); ElementAssignmentConflictCheck _conflictCheck = (ElementAssignmentConflictCheck)null; if (this.CreateConflictCheck(elementAssignment, out _conflictCheck, _actionElementMap) && !((ReInput.ControllerHelper.ConflictCheckingHelper)ReInput.get_controllers().conflictChecking).DoesElementAssignmentConflict(_conflictCheck)) { this.controllerMap.ReplaceOrCreateElementMap(elementAssignment); } this.row = (Remapping.Row)null; this.updateMode = Remapping.UpdateMode.ButtonSelectMode; ((Selectable)this.controllerSelectDropDown).set_interactable(true); this.RedrawUI(); }
private void PollKeyboardForAssignment(ElementAssignmentChange entry) { int modifierPressedCount = 0; // the number of modifier keys being pressed this cycle ControllerPollingInfo nonModifierKeyInfo = new ControllerPollingInfo(); ControllerPollingInfo firstModifierKeyInfo = new ControllerPollingInfo(); ModifierKeyFlags curModifiers = ModifierKeyFlags.None; // Check all keys being pressed at present so we can handle modifier keys foreach(ControllerPollingInfo info in ReInput.controllers.Keyboard.PollForAllKeys()) { KeyCode key = info.keyboardKey; if(key == KeyCode.AltGr) continue; // skip AltGr key because it gets fired when alt and control are held on some keyboards // determine if a modifier key is being pressed if(Keyboard.IsModifierKey(info.keyboardKey)) { // a modifier key is pressed if(modifierPressedCount == 0) firstModifierKeyInfo = info; // store the polling info for the first modifier key pressed in case its the only key pressed curModifiers |= Keyboard.KeyCodeToModifierKeyFlags(key); // add the key to the current modifier flags modifierPressedCount += 1; // count how many modifier keys are pressed } else { // this is not a modifier key if(nonModifierKeyInfo.keyboardKey != KeyCode.None) continue; // skip after the first one detected, we only need one non-modifier key press nonModifierKeyInfo = info; // store the polling info } } // Commit immediately if a non-modifier key was pressed if(nonModifierKeyInfo.keyboardKey != KeyCode.None) { // a regular key was pressed if(modifierPressedCount == 0) { // only the regular key was pressed entry.pollingInfo = nonModifierKeyInfo; // copy polling info into entry dialog.Confirm(); // finish return; } else { // one more more modifier keys was pressed too entry.pollingInfo = nonModifierKeyInfo; // copy polling info into entry entry.modifierKeyFlags = curModifiers; // set the modifier key flags in the entry dialog.Confirm(); // finish return; } } else if(modifierPressedCount > 0) { // one or more modifier keys were pressed, but no regular keys dialog.StartCloseTimer(assignmentTimeout); // reset close timer if a modifier key is pressed if(modifierPressedCount == 1) { // only one modifier is pressed, allow assigning just the modifier key // Assign the modifier key as the main key if the user holds it for 1 second if(ReInput.controllers.Keyboard.GetKeyTimePressed(firstModifierKeyInfo.keyboardKey) > 1.0f) { // key was pressed for one second entry.pollingInfo = firstModifierKeyInfo; // copy polling info into entry dialog.Confirm(); // finish return; } // Show the key that is being pressed GUILayout.Label(Keyboard.GetKeyName(firstModifierKeyInfo.keyboardKey)); } else { // more than one modifier key is pressed // do nothing because we don't want to assign modified modifier key presses such as Control + Alt, but you could if you wanted to. // Show the modifier keys being held GUILayout.Label(Keyboard.ModifierKeyFlagsToString(curModifiers)); } } }
public ElementAssignment ToElementAssignment(ControllerPollingInfo pollingInfo, ModifierKeyFlags modifierKeyFlags) { this.pollingInfo = pollingInfo; this.modifierKeyFlags = modifierKeyFlags; return(ToElementAssignment()); }
public ElementAssignment ToElementAssignment(ControllerPollingInfo pollingInfo) { this.pollingInfo = pollingInfo; return(ToElementAssignment()); }
// Polls for Gamepad Input private void GamepadPoll() { // If no controllers connected if (playerInput.controllers.joystickCount == 0) { return; } // Get current polling info in use ControllerPollingInfo pollingInfo = ReInput.controllers.polling.PollControllerForFirstElementDown(ControllerType.Joystick, playerInput.controllers.GetLastActiveController().id); // If Guide or PS Button if (pollingInfo.elementIdentifierName == "Guide" || pollingInfo.elementIdentifierName == "PS Button") { return; } // If unsuccessful if (!pollingInfo.success) { return; } bPolling = false; // Current Action Map ActionElementMap map = bAltMap ? aAltElementMaps[currentUIInputRow.SecondaryActionID] : aElementMaps[currentUIInputRow.PrimaryActionID]; // Assignment Data ElementAssignment assignment = new ElementAssignment(controlType, pollingInfo.elementType, pollingInfo.elementIdentifierId, map.axisRange, pollingInfo.keyboardKey, ModifierKeyFlags.None, map.actionId, map.axisContribution, false, map.id); // Replace element based on which map is being assigned to if (bAltMap) { altControlMap.ReplaceElementMap(assignment); if (ControllerStatusManager.currentGamepadType != eGamepadButtonType.Generic) { currentUIInputRow.secondaryButtonText.gameObject.SetActive(false); currentUIInputRow.secondaryButtonIcon.gameObject.SetActive(true); currentUIInputRow.secondaryButtonIcon.sprite = buttonImageData.GetImage(controlType, pollingInfo.elementType, pollingInfo.elementIdentifierId, map.axisRange, pollingInfo.axisPole); } else { currentUIInputRow.secondaryButtonText.gameObject.SetActive(true); currentUIInputRow.secondaryButtonIcon.gameObject.SetActive(false); currentUIInputRow.secondaryButtonText.text = pollingInfo.elementIdentifierName + SGetAxisDir(pollingInfo); } } else { controlMap.ReplaceElementMap(assignment); if (ControllerStatusManager.currentGamepadType != eGamepadButtonType.Generic) { currentUIInputRow.primaryButtonText.gameObject.SetActive(false); currentUIInputRow.primaryButtonIcon.gameObject.SetActive(true); currentUIInputRow.primaryButtonIcon.sprite = buttonImageData.GetImage(controlType, pollingInfo.elementType, pollingInfo.elementIdentifierId, map.axisRange, pollingInfo.axisPole); } else { currentUIInputRow.primaryButtonText.gameObject.SetActive(true); currentUIInputRow.primaryButtonIcon.gameObject.SetActive(false); currentUIInputRow.primaryButtonText.text = pollingInfo.elementIdentifierName + SGetAxisDir(pollingInfo); } } SettingsManager.bOptionChanged = true; CloseAssignmentWindow(); }
// Polls for Mouse Input private void MousePoll() { ControllerPollingInfo pollingInfo = new ControllerPollingInfo(); // Loop through each polling info to find which one is in use foreach (ControllerPollingInfo info in ReInput.controllers.polling.PollControllerForAllElementsDown(ControllerType.Mouse, 0)) { if (info.elementType == ControllerElementType.Axis) { // If Mouse Move X or Y, then continue if (info.elementIndex == 0 || info.elementIndex == 1) { continue; } } pollingInfo = info; } // If unsuccessful if (!pollingInfo.success) { return; } // Stop Polling bPolling = false; // Current Action Map ActionElementMap map = bAltMap ? aAltElementMaps[currentUIInputRow.SecondaryActionID] : aElementMaps[currentUIInputRow.PrimaryActionID]; // Assignment Data ElementAssignment assignment = new ElementAssignment(controlType, pollingInfo.elementType, pollingInfo.elementIdentifierId, map.axisRange, pollingInfo.keyboardKey, ModifierKeyFlags.None, map.actionId, map.axisContribution, false, map.id); string elementName = pollingInfo.elementIdentifierName; if (controlType == ControllerType.Mouse) { if (elementName == "Left Mouse Button") { elementName = "Left Click"; } else if (elementName == "Right Mouse Button") { elementName = "Right Click"; } } // Replace element based on which map is being assigned to if (bAltMap) { altControlMap.ReplaceElementMap(assignment); currentUIInputRow.secondaryButtonText.text = elementName + SGetAxisDir(pollingInfo); } else { controlMap.ReplaceElementMap(assignment); currentUIInputRow.primaryButtonText.text = elementName + SGetAxisDir(pollingInfo); } SettingsManager.bOptionChanged = true; CloseAssignmentWindow(); }
// Polls for Keyboard Input private void KeyboardPoll() { ControllerPollingInfo pollingInfo = new ControllerPollingInfo(); foreach (ControllerPollingInfo info in ReInput.controllers.Keyboard.PollForAllKeys()) { KeyCode key = info.keyboardKey; // If Key is AltGr, Command, Windows or Apple, skip it as these are keys are not supported if (key == KeyCode.AltGr) { continue; } if (key == KeyCode.LeftCommand || key == KeyCode.LeftWindows || key == KeyCode.LeftApple) { continue; } if (key == KeyCode.RightCommand || key == KeyCode.RightWindows || key == KeyCode.RightApple) { continue; } if (key != KeyCode.None) { // If the key is not pressed this frame if (!ReInput.controllers.Keyboard.GetKeyDown(key)) { return; } pollingInfo = info; break; } } // If unsuccessful if (!pollingInfo.success) { return; } // Stop polling bPolling = false; // Current Action Map ActionElementMap map = bAltMap ? aAltElementMaps[currentUIInputRow.SecondaryActionID] : aElementMaps[currentUIInputRow.PrimaryActionID]; // Replace Element based on which map is being assigned to if (bAltMap) { altControlMap.ReplaceElementMap(map.id, map.actionId, map.axisContribution, pollingInfo.keyboardKey, ModifierKeyFlags.None); currentUIInputRow.secondaryButtonText.text = pollingInfo.elementIdentifierName; } else { controlMap.ReplaceElementMap(map.id, map.actionId, map.axisContribution, pollingInfo.keyboardKey, ModifierKeyFlags.None); currentUIInputRow.primaryButtonText.text = pollingInfo.elementIdentifierName; } SettingsManager.bOptionChanged = true; CloseAssignmentWindow(); }