private bool CheckComboEvent(KeyCombo keyCombo, KeyEventType keyEventType = KeyEventType.Down)
    {
        if (keyCombo.ModKey1 != KeyCode.None && !CommonInput.GetKey(keyCombo.ModKey1))
        {
            return(false);
        }
        if (keyCombo.ModKey2 != KeyCode.None && !CommonInput.GetKey(keyCombo.ModKey2))
        {
            return(false);
        }

        switch (keyEventType)
        {
        case KeyEventType.Down:
            return(CommonInput.GetKeyDown(keyCombo.MainKey));

        case KeyEventType.Up:
            return(CommonInput.GetKeyUp(keyCombo.MainKey));

        case KeyEventType.Hold:
            return(CommonInput.GetKey(keyCombo.MainKey));

        default:
            return(CommonInput.GetKeyDown(keyCombo.MainKey));
        }
    }
Exemplo n.º 2
0
    public KeyCombo CaptureKeyCombo()
    {
        KeyCode newKey     = KeyCode.None;
        KeyCode newModKey1 = KeyCode.None;
        KeyCode newModKey2 = KeyCode.None;

        // Iterate through all possible keys
        foreach (KeyCode key in System.Enum.GetValues(typeof(KeyCode)))
        {
            if (ModKeys.Contains(key) || IgnoreKeys.Contains(key))
            {
                // If it's a modifier/ignored key we can skip it for now
                continue;
            }
            else if (CommonInput.GetKeyDown(key))
            {
                // Stop capturing if user presses escape
                if (key == KeyCode.Escape)
                {
                    return(null);
                }

                // Keep the key for later so we can return it
                newKey = key;

                // Check if any modifiers are pressed too
                foreach (KeyCode modKey in ModKeys)
                {
                    if (!CommonInput.GetKey(modKey))
                    {
                        continue;
                    }
                    // A modifier key is pressed, assign it to the first available modkey
                    if (newModKey1 == KeyCode.None)
                    {
                        // ModKey1 hasn't been assigned yet
                        newModKey1 = validateModKey(modKey);
                        if (newModKey1 == KeyCode.AltGr)
                        {
                            // Since AltGr is a strange key which sends AltGr, LeftControl and RightAlt at the same time
                            // we will only allow it to be a modifier key on its own, so we can stop checking now
                            break;
                        }
                    }
                    else if (newModKey2 == KeyCode.None)
                    {
                        // ModKey2 hasn't been assigned yet
                        // Assign it then stop checking since all modkeys assigned
                        newModKey2 = validateModKey(modKey);
                        break;
                    }
                }
            }
        }

        // Return the new key combination
        return(new KeyCombo(newKey, newModKey1, newModKey2));
    }
Exemplo n.º 3
0
 /// <summary>
 /// Checks if the left or right alt key has been pressed (AltGr sends RightAlt)
 /// </summary>
 public static bool IsAltPressed()
 {
     if (CommonInput.GetKey(KeyCode.LeftAlt) || CommonInput.GetKey(KeyCode.RightAlt))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Check if the left or right control or command keys have been pressed
 /// </summary>
 public static bool IsControlPressed()
 {
     if (CommonInput.GetKey(KeyCode.LeftControl) || CommonInput.GetKey(KeyCode.LeftControl) ||
         CommonInput.GetKey(KeyCode.LeftCommand) || CommonInput.GetKey(KeyCode.LeftCommand))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
 /// <summary>
 /// Checks if the left or right alt key has been pressed (AltGr sends RightAlt)
 /// </summary>
 public static bool IsAltPressed()
 {
     return(CommonInput.GetKey(KeyCode.LeftAlt) || CommonInput.GetKey(KeyCode.RightAlt));
 }
 /// <summary>
 /// Check if the left or right control or command keys have been pressed
 /// </summary>
 public static bool IsControlPressed()
 {
     return(CommonInput.GetKey(KeyCode.LeftControl) || CommonInput.GetKey(KeyCode.LeftControl) ||
            CommonInput.GetKey(KeyCode.LeftCommand) || CommonInput.GetKey(KeyCode.LeftCommand));
 }