Global Mouse and Keyboard Recorder

Found a nice Library here.

I just add the serialize and deserialize feature. and it work like a charm, you don't have to pay for this kind of task.

Change the macro.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GlobalMacroRecorder
{

    ///
    /// All possible events that macro can record
    ///
    [Serializable]
    public enum MacroEventType
    {
        MouseMove,
        MouseDown,
        MouseUp,
        MouseWheel,
        KeyDown,
        KeyUp
    }

    ///
    /// Series of events that can be recorded any played back
    ///
    [Serializable]
    public class MacroEvent
    {
        public MacroEventType MacroEventType;
        public MacroKeyEventArgs keyEventArgs;
        public MacroMouseEventArgs mouseEventArgs;
        public int TimeSinceLastEvent;

        public MacroEvent(MacroEventType macroEventType, MacroKeyEventArgs eventArgs, int timeSinceLastEvent)
        {
            MacroEventType = macroEventType;
            keyEventArgs = eventArgs;
            mouseEventArgs = null;
            TimeSinceLastEvent = timeSinceLastEvent;
        }

        public MacroEvent(MacroEventType macroEventType, MacroMouseEventArgs eventArgs, int timeSinceLastEvent)
        {
            MacroEventType = macroEventType;
            keyEventArgs = null;
            mouseEventArgs = eventArgs;
            TimeSinceLastEvent = timeSinceLastEvent;
        }

    }
    [Serializable]
    public class MacroKeyEventArgs
    {
        Keys KeyData; bool SupressKeyPress;
        public MacroKeyEventArgs(Keys theKeyData, bool theSupressKeyPress)
        {
            KeyData = theKeyData;
            SupressKeyPress = theSupressKeyPress;
        }
        public KeyEventArgs GetKeyEventArgs()
        {
            KeyEventArgs args = new KeyEventArgs(KeyData);
            args.SuppressKeyPress = SupressKeyPress;
            return args;
        }
    }
    [Serializable]
    public class MacroMouseEventArgs
    {
        MouseButtons button; int clicks; int x; int y; int delta;
        public MacroMouseEventArgs(MouseButtons thebutton, int theclicks, int thex, int they, int thedelta)
        {
            button = thebutton;
            clicks = theclicks;
            x = thex;
            y = they;
            delta = thedelta;
        }
        public MouseEventArgs GetMouseEventArgs()
        {
            return new MouseEventArgs(button, clicks, x, y, delta);
        }
    }
}
 

add to our button serialize and deserialize Click Event

private void button1_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.ShowDialog();
            MessageBox.Show(folderBrowserDialog1.SelectedPath);
            //Serialize the object to file
            string path=folderBrowserDialog1.SelectedPath + @"\" + txtFileName.Text + ".my";
            MessageBox.Show(path);
            Stream stream = File.Open(path, FileMode.Create);
            BinaryFormatter bformatter = new BinaryFormatter();
            bformatter.Serialize(stream,events);
            stream.Close();
            stream.Dispose();

        }

        private void button2_Click(object sender, EventArgs e)
        {
            openFileDialog1.ShowDialog();
            Stream stream = File.Open(openFileDialog1.FileName, FileMode.Open);
            BinaryFormatter bformatter = new BinaryFormatter();
            events=(List<MacroEvent>)bformatter.Deserialize(stream);
            stream.Close();
            stream.Dispose();
            playBackMacroButton_Click(this, new EventArgs() { });
        }

Share this post: | | | |
Published Friday, February 20, 2009 10:13 AM by cipto
Filed under:

Comments

No Comments