public override bool GetInput(IInputMap inputMap)
            {
                KeyboardMap map = inputMap as KeyboardMap;

                if (map == null)
                {
                    return(false);
                }

                if (!CheckDesiredModifierKeysActive(map.modifiers))
                {
                    return(false);
                }

                if (map.modifiers == ModifierKeys.None && map.keys.Count <= 0)
                {
                    return(false);
                }

                foreach (KeyCode keyCode in map.keys)
                {
                    if (!CheckKey(keyCode, inputGetFn))
                    {
                        return(false);
                    }
                }

                return(true);
            }
 // Token: 0x0600421C RID: 16924 RVA: 0x001661C4 File Offset: 0x001643C4
 private void InitMappings()
 {
     if (this.m_sectionTemplate)
     {
         this.m_sectionTemplate.gameObject.SetActive(true);
         foreach (InputMapCategory inputMapCategory in ReInput.mapping.UserAssignableMapCategories)
         {
             if (this.ControllerType == ControlMappingPanel.ControlType.Keyboard)
             {
                 KeyboardMap keyboardMapInstance = ReInput.mapping.GetKeyboardMapInstance(inputMapCategory.id, 0);
                 this.InitSections(keyboardMapInstance);
                 MouseMap mouseMapInstance = ReInput.mapping.GetMouseMapInstance(inputMapCategory.id, 0);
                 this.InitSections(mouseMapInstance);
             }
             else if (this.m_lastJoystickController != null)
             {
                 JoystickMap joystickMapInstance = ReInput.mapping.GetJoystickMapInstance((Joystick)this.m_lastJoystickController, inputMapCategory.id, 0);
                 this.InitSections(joystickMapInstance);
             }
             else
             {
                 this.m_mappingInitialized = false;
             }
         }
         this.m_sectionTemplate.gameObject.SetActive(false);
     }
 }
Пример #3
0
            public IInputMap Clone()
            {
                KeyboardMap clone = new KeyboardMap();

                clone.modifiers = modifiers;
                clone.keys.AddRange(keys);

                return(clone);
            }
            public float?GetAxis(IInputMap inputMap)
            {
                KeyboardMap map = inputMap as KeyboardMap;

                if (map == null)
                {
                    return(null);
                }

                return(GetInput(inputMap) ? (float?)1.0f : null);
            }
Пример #5
0
 public void Setup(string id)
 {
     if (String.IsNullOrEmpty(id))
     {
         _customId = IntPtr.Zero;
         _map      = new KeyboardMap(NativeMethods.GetKeyboardLayout(0));
     }
     else
     {
         _customId = NativeMethods.LoadKeyboardLayout(id, 0, out _mustUnloadLayout);
         Assert.NotEqual(IntPtr.Zero, _customId);
         _map = new KeyboardMap(_customId);
     }
 }
Пример #6
0
            public bool SetFrom(IInputMap that)
            {
                KeyboardMap kbCast = that as KeyboardMap;

                if (kbCast == null)
                {
                    Debug.LogError("Type incompatibility when trying to call SetFrom on a keyboard input map");
                    return(false);
                }

                modifiers = kbCast.modifiers;
                keys.Clear();
                keys.AddRange(kbCast.keys);

                return(true);
            }
Пример #7
0
        private void Initialize()
        {
            _stopwatch = new Stopwatch();
            _stopwatch.Start();

            _textureLock = new ReaderWriterLockSlim();

            // Set up .NET/Mono host keyboard -> PERQ mapping
            _keymap = new KeyboardMap();

            _clickFlag   = false;
            _mouseButton = 0x0;

            //
            // Kick off our SDL message loop.
            //
            _sdlThread = new Thread(SDLMessageLoopThread);
            _sdlThread.Start();
        }
Пример #8
0
 /// <summary>
 /// Saves keys
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void BtnSaveKeys(object sender, RoutedEventArgs e)
 {
     try
     {
         var kbMap = new KeyboardMap
         {
             P1B1      = GetPressedKey(TxtP1B1.Tag),
             P1B2      = GetPressedKey(TxtP1B2.Tag),
             P1B3      = GetPressedKey(TxtP1B3.Tag),
             P1B4      = GetPressedKey(TxtP1B4.Tag),
             P1B5      = GetPressedKey(TxtP1B5.Tag),
             P1B6      = GetPressedKey(TxtP1B6.Tag),
             P1Up      = GetPressedKey(TxtP1Up.Tag),
             P1Down    = GetPressedKey(TxtP1Down.Tag),
             P1Left    = GetPressedKey(TxtP1Left.Tag),
             P1Right   = GetPressedKey(TxtP1Right.Tag),
             P1Service = GetPressedKey(TxtP1Service.Tag),
             P1Start   = GetPressedKey(TxtP1Start.Tag),
             P2B1      = GetPressedKey(TxtP2B1.Tag),
             P2B2      = GetPressedKey(TxtP2B2.Tag),
             P2B3      = GetPressedKey(TxtP2B3.Tag),
             P2B4      = GetPressedKey(TxtP2B4.Tag),
             P2B5      = GetPressedKey(TxtP2B5.Tag),
             P2B6      = GetPressedKey(TxtP2B6.Tag),
             P2Up      = GetPressedKey(TxtP2Up.Tag),
             P2Down    = GetPressedKey(TxtP2Down.Tag),
             P2Left    = GetPressedKey(TxtP2Left.Tag),
             P2Right   = GetPressedKey(TxtP2Right.Tag),
             P2Service = GetPressedKey(TxtP2Service.Tag),
             P2Start   = GetPressedKey(TxtP2Start.Tag),
             TestSw    = GetPressedKey(TxtTestSw.Tag)
         };
         KeyboardHelper.Serialize(kbMap);
         Close();
     }
     catch (Exception exception)
     {
         MessageBox.Show($"Error while saving: {exception}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
     Close();
 }
Пример #9
0
 // Token: 0x0600421C RID: 16924 RVA: 0x001661C4 File Offset: 0x001643C4
 private void InitMappings()
 {
     if (this.m_sectionTemplate)
     {
         this.m_sectionTemplate.gameObject.SetActive(true);
         foreach (InputMapCategory inputMapCategory in ReInput.mapping.UserAssignableMapCategories)
         {
             if (this.ControllerType == ControlMappingPanel.ControlType.Keyboard)
             {
                 KeyboardMap keyboardMapInstance = ReInput.mapping.GetKeyboardMapInstance(inputMapCategory.id, 0);
                 MouseMap    mouseMapInstance    = ReInput.mapping.GetMouseMapInstance(inputMapCategory.id, 0);
                 // We know this name from debugging, or we can dump it.
                 if (inputMapCategory.name == "QuickSlot")
                 {
                     // Loop through our 8 actions we added via ReWired and create the mapping objects for them.
                     for (int i = 0; i < 8; i++)
                     {
                         var aid = ReInput.mapping.GetActionId(string.Format("QS_Instant{0}", i + 12));
                         ElementAssignment elementAssignment = new ElementAssignment(KeyCode.None, ModifierKeyFlags.None, aid, Pole.Positive);
                         ActionElementMap  actionElementMap;
                         keyboardMapInstance.CreateElementMap(elementAssignment, out actionElementMap);
                         mouseMapInstance.CreateElementMap(elementAssignment, out actionElementMap);
                     }
                 }
                 this.InitSections(keyboardMapInstance);
                 this.InitSections(mouseMapInstance);
             }
             else if (this.m_lastJoystickController != null)
             {
                 JoystickMap joystickMapInstance = ReInput.mapping.GetJoystickMapInstance((Joystick)this.m_lastJoystickController, inputMapCategory.id, 0);
                 this.InitSections(joystickMapInstance);
             }
             else
             {
                 this.m_mappingInitialized = false;
             }
         }
         this.m_sectionTemplate.gameObject.SetActive(false);
     }
 }
Пример #10
0
            public bool HasConflict(IInputMap other, InputAction.Properties properties)
            {
                KeyboardMap otherKbMap = other as KeyboardMap;

                if (otherKbMap == null || otherKbMap.IsEmpty)
                {
                    return(false);
                }

                KeyboardDevice.ModifierKeys manualModifierKeysPressed = KeyboardDevice.ModifierKeys.None;
                foreach (KeyCode otherKeyCode in otherKbMap.keys)
                {
                    manualModifierKeysPressed |= KeyboardDevice.ToModifierKey(otherKeyCode);
                }

                if (keys.Count <= 0 && modifiers == manualModifierKeysPressed && modifiers != KeyboardDevice.ModifierKeys.None)
                {
                    return(true);
                }

                if (modifiers != otherKbMap.modifiers)
                {
                    return(false);
                }

                foreach (KeyCode keyCode in keys)
                {
                    foreach (KeyCode otherKeyCode in otherKbMap.keys)
                    {
                        bool modifierKeyConflict = (KeyboardDevice.ToModifierKey(keyCode) & otherKbMap.modifiers) != 0;

                        if (modifierKeyConflict || keyCode == otherKeyCode)
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }
            public override bool GetInputUp(IInputMap inputMap)
            {
                KeyboardMap map = inputMap as KeyboardMap;

                if (map == null)
                {
                    return(false);
                }

                if (!CheckDesiredModifierKeysActive(map.modifiers))
                {
                    return(false);
                }

                if (map.modifiers == ModifierKeys.None && map.keys.Count <= 0)
                {
                    return(false);
                }

                // Look for at least 1 key that is coming up. The rest just need to be pressed
                bool hasInputDir = false;

                foreach (KeyCode keyCode in map.keys)
                {
                    if (!CheckKey(keyCode, inputUpFn))
                    {
                        if (!CheckKey(keyCode, inputGetFn))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        hasInputDir = true;
                    }
                }

                return(hasInputDir);
            }
Пример #12
0
 private static void UpdateActionElementRelationships(Dictionary <int[], List <ActionElementMap> > elementSourceActionLinks, Dictionary <int, ActionElementMap> storedElementMaps, InputMapCategory sourceCategory, Player player)
 {
     foreach (KeyValuePair <int[], List <ActionElementMap> > keyValuePair in elementSourceActionLinks)
     {
         if (keyValuePair.Value.SafeCount <ActionElementMap>() != 0)
         {
             int key = keyValuePair.Key[2];
             ActionElementMap oldElementMap      = storedElementMaps[key];
             KeyboardMap      firstMapInCategory = player.controllers.maps.GetFirstMapInCategory <KeyboardMap>(0, sourceCategory.id);
             if (firstMapInCategory == null)
             {
                 Debug.LogError("newControllerMap is null!");
             }
             else
             {
                 ActionElementMap firstElementMapMatch = firstMapInCategory.GetFirstElementMapMatch((ActionElementMap searchMap) => searchMap.actionId == oldElementMap.actionId);
                 if (firstElementMapMatch == null)
                 {
                     Debug.LogError("sourceMap is null!");
                 }
                 else
                 {
                     foreach (ActionElementMap actionElementMap in keyValuePair.Value)
                     {
                         ControllerMap     controllerMap     = actionElementMap.controllerMap;
                         ElementAssignment elementAssignment = new ElementAssignment(ControllerType.Keyboard, firstElementMapMatch.elementType, firstElementMapMatch.elementIdentifierId, firstElementMapMatch.axisRange, firstElementMapMatch.keyCode, firstElementMapMatch.modifierKeyFlags, firstElementMapMatch.actionId, firstElementMapMatch.axisContribution, firstElementMapMatch.invert, actionElementMap.id);
                         bool             flag = controllerMap.DeleteElementMap(actionElementMap.id);
                         ActionElementMap actionElementMap2;
                         if (!flag || !controllerMap.CreateElementMap(elementAssignment, out actionElementMap2))
                         {
                             Debug.Log("Failed to remap secondary actions");
                         }
                     }
                 }
             }
         }
     }
 }
Пример #13
0
                public void Add(IInputMap map)
                {
                    KeyboardMap kbMap = map as KeyboardMap;

                    if (kbMap != null)
                    {
                        kbMaps.Add(kbMap);
                    }

                    GamepadMap gpButtonMap = map as GamepadMap;

                    if (gpButtonMap != null)
                    {
                        gpButtonMaps.Add(gpButtonMap);
                    }

                    JoystickMap jsButtonMap = map as JoystickMap;

                    if (jsButtonMap != null)
                    {
                        jsMaps.Add(jsButtonMap);
                    }
                }
            public IInputMap GetCurrentInput(InputAction.Properties properties)
            {
                currentKeys.Clear();
                releasedModifierKeys.Clear();

                ModifierKeys modifiersActive        = ModifierKeys.None;
                bool         containsNonModifierKey = false;

                foreach (KeyCode kCode in EnumX <KeyCode> .Values)
                {
                    if ((int)kCode >= (int)KeyCode.Menu)
                    {
                        break;
                    }

                    bool isModifierKey = IsModifierKey(kCode);
                    if (UnityEngine.Input.GetKey(kCode))
                    {
                        currentKeys.Add(kCode);
                        modifiersActive |= ToModifierKey(kCode);

                        if (!isModifierKey)
                        {
                            containsNonModifierKey = true;
                        }
                    }

                    if (isModifierKey && UnityEngine.Input.GetKeyUp(kCode))
                    {
                        releasedModifierKeys.Add(kCode);
                    }
                }

                // Create map if no modifier keys are active, or if they are, they are released or have another input with it
                if (currentKeys.Count > 0 && containsNonModifierKey)
                {
                    KeyboardMap map = new KeyboardMap(modifiersActive);

                    foreach (KeyCode kCode in currentKeys)
                    {
                        if (!IsModifierKey(kCode))
                        {
                            map.Add(kCode);
                        }
                    }

                    return(map);
                }

                // If we wanted to use modifier keys as regular keys
                if (currentKeys.Count <= 0 && releasedModifierKeys.Count == 1)
                {
                    KeyboardMap map = new KeyboardMap(ModifierKeys.None);

                    foreach (KeyCode kCode in releasedModifierKeys)
                    {
                        map.Add(kCode);
                    }

                    return(map);
                }

                return(null);
            }
Пример #15
0
 protected void AssertGetKeyInput(KeyInput keyInput, char c, ModifierKeys modifierKeys)
 {
     Assert.Equal(keyInput, KeyboardMap.GetKeyInput(c, modifierKeys));
 }
Пример #16
0
 public FakeKeyboardTest()
 {
     _mockVirtualKeyboard = new MockVirtualKeyboard();
     _map = new KeyboardMap(IntPtr.Zero, _mockVirtualKeyboard);
 }
Пример #17
0
        public string CheckForErrors()
        {
            // Make sure all modifiable input commands are synchronized first.
            foreach (var command in Commands)
            {
                (command as UserCommandModifiableKeyInput)?.SynchronizeCombine();
            }

            StringBuilder errors = new StringBuilder();

            // Check for commands which both require a particular modifier, and ignore it.
            foreach (var command in EnumExtension.GetValues <UserCommand>())
            {
                if (Commands[(int)command] is UserCommandModifiableKeyInput modInput)
                {
                    if (modInput.Shift && modInput.IgnoreShift)
                    {
                        errors.AppendLine(settingsCatalog.GetStringFmt("{0} requires and is modified by Shift", commonCatalog.GetString(command.GetDescription())));
                    }
                    if (modInput.Control && modInput.IgnoreControl)
                    {
                        errors.AppendLine(settingsCatalog.GetStringFmt("{0} requires and is modified by Control", commonCatalog.GetString(command.GetDescription())));
                    }
                    if (modInput.Alt && modInput.IgnoreAlt)
                    {
                        errors.AppendLine(settingsCatalog.GetStringFmt("{0} requires and is modified by Alt", commonCatalog.GetString(command.GetDescription())));
                    }
                }
            }

            // Check for two commands assigned to the same key
            UserCommand firstCommand = EnumExtension.GetValues <UserCommand>().Min();
            UserCommand lastCommand  = EnumExtension.GetValues <UserCommand>().Max();

            for (UserCommand command1 = firstCommand; command1 <= lastCommand; command1++)
            {
                var input1 = Commands[(int)command1];

                // Modifier inputs don't matter as they don't represent any key.
                if (input1 is UserCommandModifierInput)
                {
                    continue;
                }

                for (var command2 = command1 + 1; command2 <= lastCommand; command2++)
                {
                    var input2 = Commands[(int)command2];

                    // Modifier inputs don't matter as they don't represent any key.
                    if (input2 is UserCommandModifierInput)
                    {
                        continue;
                    }

                    // Ignore problems when both inputs are on defaults. (This protects the user somewhat but leaves developers in the dark.)
                    //if (input1.PersistentDescriptor == InputSettings.DefaultCommands[(int)command1].PersistentDescriptor && input2.PersistentDescriptor == InputSettings.DefaultCommands[(int)command2].PersistentDescriptor)
                    if (input1.UniqueDescriptor == DefaultCommands[(int)command1].UniqueDescriptor &&
                        input2.UniqueDescriptor == DefaultCommands[(int)command2].UniqueDescriptor)
                    {
                        continue;
                    }

                    var unique1      = input1.GetUniqueInputs();
                    var unique2      = input2.GetUniqueInputs();
                    var sharedUnique = unique1.Where(id => unique2.Contains(id));
                    foreach (var uniqueInput in sharedUnique)
                    {
                        errors.AppendLine(settingsCatalog.GetStringFmt("{0} and {1} both match {2}", commonCatalog.GetString(command1.GetDescription()),
                                                                       commonCatalog.GetString(command2.GetDescription()), KeyboardMap.GetPrettyUniqueInput(uniqueInput)));
                    }
                }
            }

            return(errors.ToString());
        }
        public static bool InitMappingsPrefix(ControlMappingPanel __instance, ref ControlMappingSection ___m_sectionTemplate, ref bool ___m_mappingInitialized, ref Controller ___m_lastJoystickController)
        {
            if (___m_sectionTemplate)
            {
                ___m_sectionTemplate.gameObject.SetActive(true);
                foreach (InputMapCategory inputMapCategory in ReInput.mapping.UserAssignableMapCategories)
                {
                    if (__instance.ControllerType == ControlMappingPanel.ControlType.Keyboard)
                    {
                        KeyboardMap keyboardMapInstance = ReInput.mapping.GetKeyboardMapInstance(inputMapCategory.id, 0);
                        MouseMap    mouseMapInstance    = ReInput.mapping.GetMouseMapInstance(inputMapCategory.id, 0);
                        // We know this name from debugging, or we can dump it.
                        Debug.Log("Extended Quickslots - InitMappingsPrefix() inputMapCategory = " + inputMapCategory.name);
                        if (inputMapCategory.name == "QuickSlot")
                        {
                            Debug.Log("ExtendedQuickslots - Mapping Quickslots ...");
                            // Loop through our 8 actions we added via ReWired and create the mapping objects for them.
                            for (int i = 0; i < ExtendedQuickslots.numSlots; i++)
                            {
                                Debug.Log("\tMapping " + string.Format("QS_Instant{0}", i + 12));
                                var aid = ReInput.mapping.GetActionId(string.Format("QS_Instant{0}", i + 12));
                                ElementAssignment elementAssignment = new ElementAssignment(KeyCode.None, ModifierKeyFlags.None, aid, Pole.Positive);
                                keyboardMapInstance.CreateElementMap(elementAssignment, out ActionElementMap actionElementMap);
                                mouseMapInstance.CreateElementMap(elementAssignment, out actionElementMap);
                            }
                        }
                        if (inputMapCategory.name == "Actions")
                        {
                            ElementAssignment elementAssignment;
                            int aid;

                            Debug.Log("\tMapping Sit emote");
                            aid = ReInput.mapping.GetActionId("Sit_Emote");
                            elementAssignment = new ElementAssignment(KeyCode.None, ModifierKeyFlags.None, aid, Pole.Positive);
                            keyboardMapInstance.CreateElementMap(elementAssignment, out ActionElementMap actionElementMap);
                            mouseMapInstance.CreateElementMap(elementAssignment, out actionElementMap);

                            Debug.Log("\tMapping Alternate Idle Emote");
                            aid = ReInput.mapping.GetActionId("Alternate_Idle_Emote");
                            elementAssignment = new ElementAssignment(KeyCode.None, ModifierKeyFlags.None, aid, Pole.Positive);
                            keyboardMapInstance.CreateElementMap(elementAssignment, out actionElementMap);
                            mouseMapInstance.CreateElementMap(elementAssignment, out actionElementMap);
                        }

                        ControlMappingPanel_InitSections(__instance, new object[] { keyboardMapInstance });
                        ControlMappingPanel_InitSections(__instance, new object[] { mouseMapInstance });
                    }
                    else if (___m_lastJoystickController != null)
                    {
                        JoystickMap joystickMapInstance = ReInput.mapping.GetJoystickMapInstance((Joystick)___m_lastJoystickController, inputMapCategory.id, 0);
                        ControlMappingPanel_InitSections(__instance, new object[] { joystickMapInstance });
                    }
                    else
                    {
                        ___m_mappingInitialized = false;
                    }
                }
                ___m_sectionTemplate.gameObject.SetActive(false);
            }
            return(false);
        }
Пример #19
0
 public void Setup(string id)
 {
     if (String.IsNullOrEmpty(id))
     {
         _customId = IntPtr.Zero;
         _map = new KeyboardMap(NativeMethods.GetKeyboardLayout(0));
     }
     else
     {
         _customId = NativeMethods.LoadKeyboardLayout(id, 0);
         Assert.AreNotEqual(IntPtr.Zero, _customId);
         _map = new KeyboardMap(_customId);
     }
 }
Пример #20
0
 /// <summary>
 /// Gets a display string for a KeyboardMap value.
 /// </summary>
 /// <param name="keyboardMap">The keyboard map value to get a user interface display string for.</param>
 /// <returns>The display string.</returns>
 public static string ToDisplayString(this KeyboardMap keyboardMap)
 {
     return(DisplayValues[keyboardMap]);
 }
Пример #21
0
 /// <summary>
 /// Initializes a new instance of the type.
 /// </summary>
 /// <param name="keyboardMap">The value to represent.</param>
 public KeyboardMapViewModel(KeyboardMap keyboardMap)
 {
     KeyboardMap = keyboardMap;
     Map         = keyboardMap.ToDisplayString();
 }