Exemple #1
0
        /// <summary>
        /// Extends ConvertTo so that methods that return a specific type object given a Type parameter can be
        /// used as generic method and casting is not required.
        /// <example>
        /// typeconverter.ConvertTo&lt;int&gt;(value);
        /// </example>
        /// </summary>
        public static T ConvertTo <T>(this KeysConverter typeconverter, Object value)
        {
            if (typeconverter == null)
            {
                throw new ArgumentNullException("typeconverter");
            }

            return((T)typeconverter.ConvertTo(value, typeof(T)));
        }
Exemple #2
0
        /// <summary>
        /// Extends ConvertTo so that methods that return a specific type object given a Type parameter can be
        /// used as generic method and casting is not required.
        /// <example>
        /// keysconverter.ConvertTo&lt;int&gt;(context, culture, value);
        /// </example>
        /// </summary>
        public static T ConvertTo <T>(this KeysConverter keysconverter, System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, Object value)
        {
            if (keysconverter == null)
            {
                throw new ArgumentNullException("keysconverter");
            }

            return((T)keysconverter.ConvertTo(context, culture, value, typeof(T)));
        }
        /// <summary>
        /// Convert KeyCode to char. Return char MinValue if it can´t convert the value
        /// </summary>
        /// <param name="key"></param>
        /// <returns>char</returns>
        public static char KeyCodeToChar(int key)
        {
            KeysConverter kc = new KeysConverter();

            try
            {
                char keyChar = (char)kc.ConvertTo(key, typeof(char));
                return(keyChar);
            } catch (Exception)
            {
                return(char.MinValue);
            }
        }
Exemple #4
0
        private void HandleKey(Keys key)
        {
            if (!chkDirectMode.Checked)
            {
                return;
            }
            var cvt      = new KeysConverter();
            var shortcut = (string)cvt.ConvertTo(key, typeof(string));

            var preset = _buttons.FirstOrDefault(p => p.shortcut != null && p.shortcut.Equals(shortcut));

            if (preset != null)
            {
                var _ = _lgService.ApplyPreset(preset);
            }
        }
Exemple #5
0
        private LgPreset GeneratePreset(string name, string step = null, string appId = null, Keys key = Keys.None)
        {
            var preset = new LgPreset();

            var cvt      = new KeysConverter();
            var shortcut = key != Keys.None ? (string)cvt.ConvertTo(key, typeof(string)) : null;

            preset.name     = name;
            preset.appId    = appId;
            preset.shortcut = shortcut;
            if (appId == null)
            {
                preset.steps.Add(step == null ? name : step);
            }

            return(preset);
        }
Exemple #6
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);
            if (e.KeyData == (Keys.Alt | Keys.Menu) ||
                e.KeyData == (Keys.ControlKey | Keys.Control) ||
                e.KeyData == (Keys.ShiftKey | Keys.Shift))
            {
                return;
            }

            if (e.KeyData == Keys.Delete)
            {
                Text = "";
            }
            else
            {
                Text = (string)_keysConverter.ConvertTo(e.KeyData, typeof(string));
            }
            e.Handled = true;
        }
Exemple #7
0
        public bool TryProcessEvent(KeyboardEvent evnt, out string result)
        {
            result = string.Empty;
            if (!evnt.IsChar)
            {
                Keys keyCode = evnt.Keys & Keys.KeyCode;

                switch (keyCode)
                {
                case Keys.LControlKey:
                case Keys.RControlKey:
                case Keys.LShiftKey:
                case Keys.RShiftKey:
                case Keys.RMenu:
                case Keys.LMenu:
                    return(true);
                }

                if (evnt.Keys.HasFlag((Keys)524288))
                {
                    return(false);
                }
                if (!evnt.Keys.HasFlag(Keys.Control) && !evnt.Keys.HasFlag(Keys.Alt))
                {
                    return(false);
                }
                if (evnt.Keys == Keys.Alt || evnt.Keys == Keys.Control)
                {
                    return(false);
                }

                //Keys n = keyCode & ~(Keys.LControlKey | Keys.RControlKey | Keys.LShiftKey | Keys.RShiftKey | Keys.LMenu | Keys.RMenu);
                //if (n == Keys.None) return true;

                result = (string)_keysConverter.ConvertTo(evnt.Keys, typeof(string));
                return(true);
            }

            return(false);
        }
Exemple #8
0
 private void HandleKey(Keys key)
 {
     var cvt      = new KeysConverter();
     var shortcut = (string)cvt.ConvertTo(key, typeof(string));
 }
Exemple #9
0
 public static Enum[] ConvertToEnumArray(Keys keys)
 {
     return((Enum[])kc.ConvertTo(keys, typeof(Enum[])));
 }