Ejemplo n.º 1
0
        public void ProcessShortcut(Keys key, bool ctrl, bool alt, bool shift)
        {
            bool hasKeyTwo = false;

            try
            {
                if (gateway == null)
                {
                    return;
                }

                if ((ctrl && alt) || (ctrl && shift) || (alt && shift))
                {
                    hasKeyTwo = true;
                }

                foreach (Shortcut s in this.shortcuts)
                {
                    if (s.KeyOne == Keys.Alt && alt || s.KeyOne == Keys.Control && ctrl || s.KeyOne == Keys.Shift && shift)
                    {
                        if (s.KeyTwo == Keys.None && hasKeyTwo || s.KeyTwo != Keys.None && !hasKeyTwo)
                        {
                            continue;
                        }
                        else if (s.KeyTwo == Keys.Alt && !alt || s.KeyTwo == Keys.Control && !ctrl || s.KeyTwo == Keys.Shift && !shift)
                        {
                            continue;
                        }

                        if (s.KeyThree == key)
                        {
                            ShowBallonTip(s.Name.ToString());

                            // execute action

                            foreach (Action a in s.Actions)
                            {
                                if (a.Toggle && a.Who == WHO.Lighting)
                                {
                                    lock (toggleActions)
                                    {
                                        if (!toggleActions.ContainsKey(a.Where))
                                        {
                                            toggleActions[a.Where] = a;

                                            if (lighting == null)
                                            {
                                                lighting = new Lighting(gateway);
                                            }

                                            lighting.GetLightStatus(a.Where);
                                        }
                                    }
                                }
                                else
                                {
                                    ExecuteAction(a);
                                }
                            }

                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message, "MyHomeShortcut", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }