private static void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e) { System.IntPtr foreground; if ((foreground = AutoClicker.FindWindow(foregroundWindow, null)) == AutoClicker.hWnd) { SendKeys.SendWait("{Y}"); } else { System.Timers.Timer aTimer = (System.Timers.Timer)source; aTimer.Stop(); } }
private void button4_Click(object sender, EventArgs e) { foregroundWindow = textBox_msAppTitle.Text; if ((AutoClicker.hWnd = AutoClicker.FindWindow(foregroundWindow, null)) != IntPtr.Zero) { AutoClicker.RegisterHotKey(this.Handle, 10, 0x0002, 0x11);//Ctrl AutoClicker.SetForegroundWindow(AutoClicker.hWnd); System.Timers.Timer aTimer = new System.Timers.Timer(); aTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent); // Set the Interval to 5 seconds. aTimer.Interval = (double)numericUpDown1.Value; aTimer.Enabled = true; } else { MessageBox.Show("Application Window not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } }