예제 #1
0
 public KeyBinding(
     string callback,
     int soundId,
     KeyWithModifiers key,
     KeyWithModifiers comboKey,
     UIVisibility uiVisibility,
     string description
     )
 {
     Callback     = callback;
     SoundId      = soundId;
     Key          = key;
     ComboKey     = comboKey;
     UIVisibility = uiVisibility;
     Description  = description;
 }
예제 #2
0
 private static void SendDownKeystrokes(KeyWithModifiers keyWithModifiers)
 {
     //send down keystrokes
     if ((keyWithModifiers.Modifiers & KeyModifiers.Shift) == KeyModifiers.Shift)
     {
         KeyAndMouseFunctions.SendKey((ushort)ScanCodes.LShift, true, false);
     }
     if ((keyWithModifiers.Modifiers & KeyModifiers.Alt) == KeyModifiers.Alt)
     {
         KeyAndMouseFunctions.SendKey((ushort)ScanCodes.LMenu, true, false);
     }
     if ((keyWithModifiers.Modifiers & KeyModifiers.Ctrl) == KeyModifiers.Ctrl)
     {
         KeyAndMouseFunctions.SendKey((ushort)ScanCodes.LControl, true, false);
     }
     KeyAndMouseFunctions.SendKey((ushort)keyWithModifiers.ScanCode, true, false);
 }
예제 #3
0
        public static bool TryParse(string input, out KeyBinding keyBinding)
        {
            keyBinding = null;
            if (input == null)
            {
                return(false);
            }

            var tokenList = Util.Tokenize(input);

            if (tokenList.Count < 8)
            {
                return(false);
            }

            var callback = tokenList[0];

            int soundId;
            var parsed = Int32.TryParse(tokenList[1], out soundId);

            if (!parsed)
            {
                return(false);
            }


            int keyScancode;

            if (tokenList[3] != null && tokenList[3].StartsWith("0x", StringComparison.OrdinalIgnoreCase))
            {
                parsed = Int32.TryParse(tokenList[3].ToLower().Replace("0x", string.Empty),
                                        NumberStyles.HexNumber, CultureInfo.InvariantCulture, out keyScancode);
            }
            else
            {
                parsed = Int32.TryParse(tokenList[3], out keyScancode);
            }
            if (!parsed)
            {
                return(false);
            }

            int keyModifiers;

            parsed = Int32.TryParse(tokenList[4], out keyModifiers);
            if (!parsed)
            {
                return(false);
            }

            var keyWithModifiers = new KeyWithModifiers(keyScancode, (KeyModifiers)keyModifiers);

            int comboKeyScancode;

            if (tokenList[5].StartsWith("0x", StringComparison.OrdinalIgnoreCase))
            {
                parsed = Int32.TryParse(tokenList[5].ToLowerInvariant().Replace("0x", string.Empty),
                                        NumberStyles.HexNumber, CultureInfo.InvariantCulture, out comboKeyScancode);
            }
            else
            {
                parsed = Int32.TryParse(tokenList[5], out comboKeyScancode);
            }
            if (!parsed)
            {
                return(false);
            }

            int comboKeyModifiers;

            parsed = Int32.TryParse(tokenList[6], out comboKeyModifiers);
            if (!parsed)
            {
                return(false);
            }

            var comboKeyWithModifiers = new KeyWithModifiers(comboKeyScancode, (KeyModifiers)comboKeyModifiers);

            int uiVisibility;

            parsed = Int32.TryParse(tokenList[7], out uiVisibility);
            if (!parsed)
            {
                return(false);
            }

            var description = "\"\"";

            if (tokenList.Count > 8)
            {
                var firstQuote = input.IndexOf("\"", StringComparison.OrdinalIgnoreCase);
                if (firstQuote > 0)
                {
                    description = input.Substring(firstQuote);
                }
                else
                {
                    return(false);
                }
            }
            keyBinding = new KeyBinding(callback, soundId, keyWithModifiers, comboKeyWithModifiers, (UIVisibility)uiVisibility, description);
            return(true);
        }