Exemplo n.º 1
0
        private void OnTick(object sender, EventArgs args)
        {
            // Check keys
            foreach (var key in Enum.GetValues(typeof(Keys)).Cast <Keys>())
            {
                var keyDown = ModAPI.Input.GetButton(key.ToString());
                if (keyDown && !KeysDown.Contains(key))
                {
                    KeysDown.Add(key);

                    // Notify listeners for key down
                    if (OnKeyDown != null)
                    {
                        foreach (var action in OnKeyDown.GetInvocationList())
                        {
                            try
                            {
                                action.DynamicInvoke(this, new KeyEventArgs(key));
                            }
                            catch (Exception e)
                            {
                                Logger.Exception("Exception while notifying OnKeyDown listener: " + action.GetType().Name, e);
                            }
                        }
                    }
                }
                else if (!keyDown && KeysDown.Contains(key))
                {
                    KeysDown.Remove(key);

                    // Notify listeners for key up
                    if (OnKeyUp != null)
                    {
                        foreach (var action in OnKeyUp.GetInvocationList())
                        {
                            try
                            {
                                action.DynamicInvoke(this, new KeyEventArgs(key));
                            }
                            catch (Exception e)
                            {
                                Logger.Exception("Exception while notifying OnKeyDown listener: " + action.GetType().Name, e);
                            }
                        }
                    }
                }
            }
        }