Esempio n. 1
0
 private static Script FromListViewItem(ListViewItem item)
 {
     return(new Script(
                item.Tag + "",
                item.Text,
                SysEvent.GetFromShort(item.SubItems[1].Text)
                ));
 }
Esempio n. 2
0
        public void AddScript(Script script)
        {
            if (!allEvents.Contains(script.TriggerEvent))
            {
                SysEvent info = script.TriggerEvent;
                switch (script.TriggerEvent.Id)
                {
                case SysEvent.PROCEXIT:
                    Watcher.OnProcessExit += info.OnEvent;
                    break;

                case SysEvent.PROCSTART:
                    Watcher.OnProcessStart += info.OnEvent;
                    break;

                case SysEvent.WINCLOSE:
                    Watcher.OnWindowClose += info.OnEvent;
                    break;

                case SysEvent.WINFOCUS:
                    Watcher.OnWindowFocus += info.OnEvent;
                    break;

                case SysEvent.WINHIDE:
                    Watcher.OnWindowHide += info.OnEvent;
                    break;

                case SysEvent.WINMAXIMIZE:
                    Watcher.OnWindowMaximize += info.OnEvent;
                    break;

                case SysEvent.WINMINIMIZE:
                    Watcher.OnWindowMinimize += info.OnEvent;
                    break;

                case SysEvent.WINNOFOCUS:
                    Watcher.OnWindowNoFocus += info.OnEvent;
                    break;

                case SysEvent.WINOPEN:
                    Watcher.OnWindowOpen += info.OnEvent;
                    break;

                case SysEvent.WINSHOW:
                    Watcher.OnWindowShow += info.OnEvent;
                    break;

                case SysEvent.WINTITLECHANGE:
                    Watcher.OnWindowTitleChange += info.OnEvent;
                    break;
                }
                allEvents.Add(info);
            }
            script.TriggerEvent.AddScript(script);
        }
Esempio n. 3
0
 private void EditScript_Load(object sender, EventArgs e)
 {
     textBox1.Text = item.SubItems[2].Text;
     if (item.Tag != null)
     {
         openFileDialog1.FileName = item.Tag.ToString();
         label4.Text = "Script Configuration";
     }
     comboBox2.SelectedIndex = 1;
     if (!item.SubItems[1].Text.Equals(""))
     {
         if (item.SubItems[1].Text.Contains("Process"))
         {
             comboBox2.SelectedIndex = 0;
         }
         comboBox1.SelectedItem =
             SysEvent.GetFromShort(item.SubItems[1].Text).PlainText.Present;
     }
     textBox2.Text = item.Text;
 }
Esempio n. 4
0
        public static Script FromXmlNode(XmlNode node)
        {
            Script script = new Script(node.SelectSingleNode("path").InnerText, ScriptLanguage.Native);

            try {
                script.Language = (ScriptLanguage)Enum.Parse(typeof(ScriptLanguage), node.SelectSingleNode("lang").InnerText);
            }
            catch {
                script.Language = ScriptLanguage.Native;
            }

            XmlNode nodeTrig = node.SelectSingleNode("trigger");

            int eventId = int.Parse(nodeTrig.Attributes["event"].InnerText);

            script.TriggerEvent = SysEvent.FromId(eventId);
            script.TriggerName  = nodeTrig.InnerText;

            return(script);
        }
Esempio n. 5
0
 private void saveButton_Click(object sender, EventArgs e)
 {
     if (!File.Exists(openFileDialog1.FileName))
     {
         toolTip1.Show("This file does not exist.", textBox1);
     }
     else if (comboBox1.SelectedItem == null)
     {
         toolTip1.Show("Scripts must be associated with an event.", comboBox1);
     }
     else if (textBox2.Text.Equals(""))
     {
         toolTip1.Show("The window/process must have a name", textBox2);
     }
     else
     {
         DialogResult          = System.Windows.Forms.DialogResult.Yes;
         item.Text             = textBox2.Text;
         item.Tag              = openFileDialog1.FileName;
         item.SubItems[1].Text = SysEvent.GetFromPlainText(comboBox1.SelectedItem.ToString()).Name;
         item.SubItems[2].Text = textBox1.Text;
         Close();
     }
 }
Esempio n. 6
0
        private void WinWatcher(object sender, DoWorkEventArgs e)
        {
            Dictionary <IntPtr, Window> knownWindows = GetWindows();

            while (!Cancel)
            {
                Thread.Sleep(100); // no cpu hogging
                IntPtr         top         = GetForegroundWindow();
                Stack <IntPtr> openWindows = WinEnum.Enum();

                var closed = knownWindows.Keys.Except(openWindows).ToArray(); // 3-21-15 It needs to be copied. Don't use the ExceptIterator

                if (OnWindowClose == null)
                {
                    foreach (IntPtr hwnd in closed)
                    {
                        knownWindows.Remove(hwnd);
                    }
                }
                else
                {
                    foreach (IntPtr hwnd in closed)
                    {
                        Window win = knownWindows[hwnd];
                        if (!win.IsTitleEmpty())
                        {
                            OnWindowClose.Invoke(win, EventArgs.Empty);
                        }
                        knownWindows.Remove(hwnd);
                    }
                }

                while (openWindows.Count > 0)
                {
                    IntPtr hwnd = openWindows.Pop();
                    Window win;
                    if (knownWindows.TryGetValue(hwnd, out win))
                    {
                        win.Update(top == hwnd);
                        while (win.QueueCount > 0)
                        {
                            SysEvent sysEvent = win.Dequeue();
                            if (OnWindowMinimize != null && sysEvent == SysEvent.OnWindowMinimize)
                            {
                                OnWindowMinimize.Invoke(win, EventArgs.Empty);
                            }
                            if (OnWindowMaximize != null && sysEvent == SysEvent.OnWindowMaximize)
                            {
                                OnWindowMaximize.Invoke(win, EventArgs.Empty);
                            }
                            if (OnWindowTitleChange != null && sysEvent == SysEvent.OnWindowTitleChange)
                            {
                                OnWindowTitleChange.Invoke(win, EventArgs.Empty);
                            }
                            if (OnWindowFocus != null && sysEvent == SysEvent.OnWindowFocus)
                            {
                                OnWindowFocus.Invoke(win, EventArgs.Empty);
                            }
                            if (OnWindowNoFocus != null && sysEvent == SysEvent.OnWindowNoFocus)
                            {
                                OnWindowNoFocus.Invoke(win, EventArgs.Empty);
                            }
                            if (OnWindowHide != null && sysEvent == SysEvent.OnWindowHide)
                            {
                                OnWindowHide.Invoke(win, EventArgs.Empty);
                            }
                            if (OnWindowShow != null && sysEvent == SysEvent.OnWindowShow)
                            {
                                OnWindowShow.Invoke(win, EventArgs.Empty);
                            }
                        }
                    }
                    else
                    {
                        win = new Window(hwnd, top == hwnd);
                        if (OnWindowOpen != null && !win.IsTitleEmpty())
                        {
                            OnWindowOpen.Invoke(win, EventArgs.Empty);
                        }
                        knownWindows.Add(hwnd, win);
                    }
                }
            }
            e.Cancel = true;
        }
Esempio n. 7
0
 public Script(string file, ScriptLanguage lang, string triggerName, SysEvent triggerEvent)
     : this(file, lang)
 {
     TriggerEvent = triggerEvent;
     TriggerName  = triggerName;
 }
Esempio n. 8
0
 public Script(string file, string triggerName, SysEvent triggerEvent)
     : this(file)
 {
     TriggerEvent = triggerEvent;
     TriggerName  = triggerName;
 }