public void add(string dest, string src) { exListViewItem lv = new exListViewItem(DateTime.Now.ToShortDateString() + ": " + DateTime.Now.ToShortTimeString()); lv.SubItems.Add(dest); lv.SubItems.Add(src); LogView.Items.Add(lv); LogView.ClearHilights(); LogView.ToggleHilight("Focus Attack", false, 1, 2); LogView.ToggleHilight("Reset Focus", false, 2, 2); LogView.ToggleHilight("Forced Focus", false, 2, 2); LogView.ToggleHilight("Forced Kill", false, 2, 2); LogView.ToggleHilight("Retrying Focus", false, 2, 2); lv.EnsureVisible(); }
// Main Guts private void TimerTick(object sender, EventArgs e) { List <SimpleProcs> processes = Sys.GellAll(); #region Update Listview // Set all listitem items tags to false foreach (ListViewItem lv in lvProcs.Items) { lv.Tag = "false"; } // Add Any New Items and set tag to true foreach (SimpleProcs thisProc in processes) { if (!lvProcs.Items.ContainsKey(thisProc.idStr)) { exListViewItem lv = new exListViewItem(thisProc.Name); lv.ImageIndex = 0; lv.Name = thisProc.idStr; lv.Tag = "true"; lv.SubItems.Add(thisProc.idStr); if (Watched.Contains(lv.Text)) { lv.ImageIndex = 2; } else { lv.ImageIndex = 1; lv.Hilight = false; } lvProcs.Items.Add(lv); } else // Existing item, set tag to true { exListViewItem tmp = (exListViewItem)lvProcs.Items[lvProcs.Items.IndexOfKey(thisProc.idStr)]; tmp.Tag = "true"; if (Watched.Contains(tmp.Text)) { tmp.ImageIndex = 2; } else { tmp.ImageIndex = 0; tmp.Hilight = false; } } } // Remove items with a tag value of false foreach (ListViewItem lv in lvProcs.Items) { if (lv.Tag.ToString() == "false") { lvProcs.Items.Remove(lv); } } #endregion #region Focus shift detection (Update List) foreach (exListViewItem lv in lvProcs.Items) { SimpleProcs thisItem = new SimpleProcs(lv.Text, lv.Name); // Check if the window has focus if (API.ApplicationIsActivated(thisItem.idStr)) { // Watched pross switch if (Watched.Contains(thisItem.Name)) { attacks++; sbAttacks.Text = "Focus Attacks: " + attacks; API.Activate(lastFocus.idStr); if (!isAttack) { logger.add(thisItem.Name + " (" + thisItem.id + ")", "Focus Attack"); logger.add(lastFocus.Name + " (" + lastFocus.id + ")", "Reset Focus"); isAttack = true; } else { logger.add(lastFocus.Name + " (" + lastFocus.id + ")", "Retrying Focus"); } } else // Normal pross switch { isAttack = false; if (thisItem.id != lastFocus.id) { logger.add(thisItem.Name + " (" + thisItem.id + ")", lastFocus.Name + " (" + lastFocus.idStr + ")"); } // Set normal focused process lv.ImageIndex = 1; lv.ToolTipText = "Active"; lv.Hilight = true; lastFocus.Name = lv.Text; lastFocus.idStr = lv.Name; if (mnuScroll.Checked) { lv.EnsureVisible(); } } } else // Reset appearance, Not focused { if (lv.ImageIndex == 2) { lv.Hilight = true; lv.HilightIndex = 2; } if (lv.ImageIndex == 1) { lv.ImageIndex = 0; lv.Hilight = false; } } sbProcesses.Text = "Processes: " + lvProcs.Items.Count; } #endregion }