コード例 #1
0
 void HandleCommandManagerKeyPressed(object sender, KeyPressArgs e)
 {
     events.Add(new KeyPressEvent()
     {
         Key = e.Key, Modifiers = e.Modifiers
     });
 }
コード例 #2
0
ファイル: GameConsole.cs プロジェクト: ttou73/IronStar
        void Keyboard_FormKeyPress(object sender, KeyPressArgs e)
        {
            if (!isShown)
            {
                return;
            }
            switch (e.KeyChar)
            {
            case Tilde: break;

            case Backspace: editBox.Backspace(); break;

            case Enter: ExecCmd(); editBox.Enter(); break;

            case Escape: break;

            case Tab: TabCmd(); break;

            default: editBox.TypeChar(e.KeyChar); break;
            }

            // Run AutoComplete twice on TAB for better results :
            AutoComplete();

            RefreshEdit();
        }
コード例 #3
0
ファイル: PreviewWindowManager.cs プロジェクト: wjohnke/CSS18
 static void HandleKeyPressed(object sender, KeyPressArgs e)
 {
     if (e.Key == Gdk.Key.Escape)
     {
         DestroyWindow();
     }
 }
コード例 #4
0
        private void CheckMethodAttachedEvent(MethodInfo method, ConsoleKeyInfo keyInfo)
        {
            var keyAttributes = method.GetCustomAttributes().OfType <KeyAttribute>()
                                .Where(ka => !string.IsNullOrEmpty(ka.Event));

            var args = new KeyPressArgs(keyInfo);

            foreach (var attribute in keyAttributes)
            {
                this.RaiseEvent(attribute.Event, args);
            }
        }
コード例 #5
0
        void HandleCommandManagerKeyPressed(object sender, KeyPressArgs e)
        {
            uint unicode = Gdk.Keyval.ToUnicode(e.KeyValue);

            if (pendingText != null)
            {
                if (pendingModifiers != e.Modifiers || unicode == 0)
                {
                    CompleteStringEvent(pendingText.ToString(), pendingModifiers);
                }
                else
                {
                    pendingText.Append((char)unicode);
                    return;
                }

                // If text event has been completed, then we need to reset the pending events
                if (unicode != 0)
                {
                    pendingText = new StringBuilder();
                    pendingText.Append((char)unicode);
                    pendingModifiers = e.Modifiers;
                }
                else
                {
                    // Don't have a unicode key, so just issue a standard key event
                    events.Add(new KeyPressEvent {
                        Key = e.Key, Modifiers = e.Modifiers
                    });
                    pendingText      = null;
                    pendingModifiers = Gdk.ModifierType.None;
                }
            }
            else
            {
                if (unicode == 0)
                {
                    events.Add(new KeyPressEvent()
                    {
                        Key = e.Key, Modifiers = e.Modifiers
                    });
                    return;
                }

                pendingText = new StringBuilder();
                pendingText.Append((char)unicode);
                pendingModifiers = e.Modifiers;
            }
        }
コード例 #6
0
        public virtual bool Response(ConsoleKeyInfo chr)
        {
            var type     = GetType();
            var boolType = typeof(bool);

            var methods = type.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic)
                          .Select(mi => new
            {
                Attributes = mi.GetCustomAttributes().OfType <KeyAttribute>(),
                MethodInfo = mi
            })
                          .Where(a => a.Attributes.SelectMany(ca => ca.Chars).Contains(chr.Key))
                          .OrderBy(a => a.Attributes.Select(ka => ka.Order).DefaultIfEmpty(0).Sum())
                          .Select(a => a.MethodInfo)
                          .ToList();

            if (methods.Count <= 0)
            {
                return(false);
            }

            foreach (var method in methods)
            {
                try
                {
                    object[] paramenters;
                    var      paramsInfo = method.GetParameters();

                    switch (paramsInfo.Length)
                    {
                    case 0:
                        paramenters = null;
                        break;

                    case 1:
                    case 2:
                        paramenters = paramsInfo.Select(pi => ExtractParameter(chr, pi, method.Name)).ToArray();
                        break;

                    default:
                        throw new MethodAccessException($"Unknow parameters in the method {method.Name}");
                    }


                    var result = method.Invoke(this, paramenters);

                    if (method.ReturnType == boolType && result is bool ret)
                    {
                        return(ret);
                    }
                }
                finally
                {
                    var args = new KeyPressArgs(chr);
                    KeyPressed?.Invoke(this, args);
                    CheckMethodAttachedEvent(method, chr);
                }
            }

            return(true);
        }
コード例 #7
0
 public void PerformKeyPress(KeyPressArgs args)
 {
     KeyPress?.Invoke(this, args);
 }
コード例 #8
0
 private static void Button_KeyPress(object sender, KeyPressArgs args)
 {
     Console.WriteLine("Button_KeyPress");
 }