/// <summary> /// Copies and pastes the given macro. /// </summary> /// <param name="macro"></param> /// <param name="args"></param> private void CopyAndPasteMacro(Macro macro, MacroEvent e) { // Saves the current clipboard string clipboard = Clipboard.GetText(); // Copies the text to the clipboard Clipboard.SetText(macro.Text); // Performs a manual paste of the clipboard System.Threading.Thread.Sleep(1000); SendKeys.Send(ctrlV); // Restores the clipboard Clipboard.SetText(clipboard); e.Found = true; }
private void button2_Click(object sender, EventArgs e) { _macroEvents = new List <MacroEvent>(); OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = "c://"; openFileDialog.Filter = "文本文件|*.txt|所有文件|*.*"; openFileDialog.RestoreDirectory = true; openFileDialog.FilterIndex = 1; if (openFileDialog.ShowDialog() == DialogResult.OK) { string fName = openFileDialog.FileName; FileStream fs = new FileStream(fName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); int counter = 0; string line; // Read the file and display it line by line. System.IO.StreamReader file = new System.IO.StreamReader(fs); while ((line = file.ReadLine()) != null) { System.Console.WriteLine(line); lines.Add(line); counter++; } for (int i = 0; i < lines.Count - 1; i = i + 3) { MacroEvent temp = new MacroEvent(MacroEventType.KeyDown, new EventArgs(), Convert.ToInt32(lines[i + 2])); var tempenvent = new KeyEventArgs((Keys)Enum.Parse(typeof(Keys), lines[i])); //tempenvent.KeyValue = Convert.ToInt32(lines[i + 1]); temp.EventArgs = tempenvent; _macroEvents.Add(temp); } while (true) { Playback(); //if (s.KeyCode == Keys.Enter) // break; } file.Close(); System.Console.WriteLine("There were {0} lines.", counter); } }
/// <summary> /// Sets up a macro to the clipboard and pastes it wherever the user is. /// </summary> private void SetMacro() { Macro macro = GetMacro(); // Emits the event with the user search and if it has been found. MacroEvent e = new MacroEvent { UserText = macroName, Found = false }; if (macro != null) { CopyAndPasteMacro(macro, e); } MacroEventHandler.Invoke(e, null); // Reset the macroName. macroName = null; pressedAndpersand = false; }
private void OnPlayback(object sender, MacroEvent e) { switch (e.KeyMouseEventType) { case MacroEventType.MouseMove: var mouseEvent = (System.Windows.Forms.MouseEventArgs)e.EventArgs; LogMouseLocation(mouseEvent.X, mouseEvent.Y); break; case MacroEventType.MouseWheel: mouseEvent = (System.Windows.Forms.MouseEventArgs)e.EventArgs; LogMouseWheel(mouseEvent.Delta); break; case MacroEventType.MouseDown: case MacroEventType.MouseUp: mouseEvent = (System.Windows.Forms.MouseEventArgs)e.EventArgs; Log(string.Format("Mouse {0}\t\t{1}\t\tSimulator\n", mouseEvent.Button, e.KeyMouseEventType)); break; case MacroEventType.MouseDownExt: MouseEventExtArgs downExtEvent = (MouseEventExtArgs)e.EventArgs; if (downExtEvent.Button != MouseButtons.Right) { Log(string.Format("Mouse Down \t {0}\t\t\tSimulator\n", downExtEvent.Button)); return; } Log(string.Format("Mouse Down \t {0} Suppressed.\t\tSimulator\n", downExtEvent.Button)); downExtEvent.Handled = true; break; case MacroEventType.MouseWheelExt: MouseEventExtArgs wheelEvent = (MouseEventExtArgs)e.EventArgs; labelWheel.Content = string.Format("Wheel={0:000}", wheelEvent.Delta); Log("Mouse Wheel Move Suppressed.\t\tSimulator\n"); wheelEvent.Handled = true; break; case MacroEventType.MouseDragStarted: Log("MouseDragStarted\t\tSimulator\n"); break; case MacroEventType.MouseDragFinished: Log("MouseDragFinished\t\tSimulator\n"); break; case MacroEventType.MouseDoubleClick: mouseEvent = (System.Windows.Forms.MouseEventArgs)e.EventArgs; Log(string.Format("Mouse {0}\t\t{1}\t\tSimulator\n", mouseEvent.Button, e.KeyMouseEventType)); break; case MacroEventType.KeyPress: var keyEvent = (KeyPressEventArgs)e.EventArgs; Keys key = (Keys)Enum.Parse(typeof(Keys), ((int)Char.ToUpper(keyEvent.KeyChar)).ToString()); Log(string.Format("Key {0}\t\t{1}\t\tSimulator\n", key, e.KeyMouseEventType)); break; case MacroEventType.KeyDown: case MacroEventType.KeyUp: var kEvent = (System.Windows.Forms.KeyEventArgs)e.EventArgs; Log(string.Format("Key {0}\t\t{1}\t\tSimulator\n", kEvent.KeyCode, e.KeyMouseEventType)); break; default: break; } }
/// <summary> /// Adds a new event to the end of this macro. /// </summary> /// <param name="newEvent">The event to add.</param> public void AddEvent(MacroEvent newEvent) { events.Add(newEvent); }