Exemplo n.º 1
0
 public override bool Equals(object obj)
 {
     if (obj == null || !(obj is Hotkey))
     {
         return(false);
     }
     else
     {
         Hotkey hotkey = (Hotkey)obj;
         return
             ((this._hotkeyName == hotkey.GetName()) &&
              (this._primaryHotkey.All(t => hotkey.GetPrimaryHotkey().Contains(t)) &&
               (hotkey.GetPrimaryHotkey().All(h => _primaryHotkey.Contains(h)))) &&
              (this._secondaryHotkey.All(s => hotkey.GetSecondaryHotkey().Contains(s)) &&
               (hotkey.GetSecondaryHotkey().All(shk => _secondaryHotkey.Contains(shk)))));
     }
 }
Exemplo n.º 2
0
    /// <summary>
    /// Attributes the keycodes being pressed by user at this moment to
    /// the hotkey name.
    /// </summary>
    /// <param name="hotkeyName">Valid name of a hotkey (refer to static hotkey var names above)</param>
    /// <param name="isPrimary">Is this hotkey a primary or secondary hotkey?</param>
    public static void SetHotkeyBasedOnInput(string hotkeyName, bool isPrimary)
    {
        /* Get's the keycodes of the keys currently being held down! */
        KeyCode[] newKeyCodes = GetInputKeyCodes();

        /* As long as any keys are being pressed... */
        if (newKeyCodes.Length > 0)
        {
            Hotkey oldHotkey = GetHotkey(hotkeyName); // which one we're replacing!

            Hotkey newHotkey;

            /* If it's a primary hotkey, we don't need to do anything special */
            if (isPrimary)
            {
                newHotkey = new Hotkey(hotkeyName, newKeyCodes, oldHotkey.GetSecondaryHotkey());
            }
            /* Else we need to add shift to the key codes, if it's not already there */
            else
            {
                /* Since it's a secondary hotkey, it techincally needs to also have shift in it! */
                if (!(newKeyCodes.Any(key => key == KeyCode.LeftShift)))
                {
                    List <KeyCode> list = newKeyCodes.ToList();
                    list.Add(KeyCode.LeftShift);
                    newKeyCodes = list.ToArray();
                }
                newHotkey = new Hotkey(hotkeyName, oldHotkey.GetPrimaryHotkey(), newKeyCodes);
            }

            if (!SetHotkey(oldHotkey, newHotkey))
            {
                Debug.LogWarning("No Hotkey '" + oldHotkey.ToString() + "' found for SetHotkey.");
            }
        }
    }