public MacroEvent_Mouse(MouseEvent _event, eMouseButton _button)
        {
            Event = _event;
            Button = _button;

            INPUT keyInput = new INPUT();
            keyInput.type = 0;
            MOUSEINPUT mInput = new MOUSEINPUT();

            eMouseCommand command = eMouseCommand.Move;
            if (Button == eMouseButton.LDOWN) command = eMouseCommand.LDown;
            if (Button == eMouseButton.LUP) command = eMouseCommand.LUp;
            if (Button == eMouseButton.RDOWN) command = eMouseCommand.RDown;
            if (Button == eMouseButton.RUP) command = eMouseCommand.RUp;
            if (Button == eMouseButton.MWheel) command = eMouseCommand.MWheel;
            if (Button == eMouseButton.MHWheel) command = eMouseCommand.HWHeel;

            mInput.dx = 0;
            mInput.dy = 0;
            mInput.mouseData = Event.mouseData;
            mInput.time = 0;
            mInput.dwExtraInfo = Event.extraInfo;
            mInput.dwFlags = (uint)command;

            keyInput.iUinion.mi = mInput;

            InputList[0] = keyInput;

            inputSize = Marshal.SizeOf(InputList[0]);
        }
Esempio n. 2
0
        private void loadAMacroToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string filePath = string.Empty;
            using(OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Filter = "Macro File|*.bmr";
                if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    return;
                filePath = ofd.FileName;
            }
            try
            {
                IMacroEvent[] loadedEvents = null;
                using (FileStream fs = new FileStream(filePath, FileMode.Open))
                using (BinaryReader br = new BinaryReader(fs))
                {
                    loadedEvents = new IMacroEvent[br.ReadInt32()];
                    int eventIndex = 0;
                    while(fs.Position != fs.Length)
                    {
                        MacroEventType mType = (MacroEventType)br.ReadByte();
                        if(mType == MacroEventType.Delay)
                        {
                            loadedEvents[eventIndex] = new MacroEvent_Delay(br.ReadInt32());
                        }

                        if(mType == MacroEventType.Keyboard)
                        {
                            eKeyboardEvent kbEvent = (eKeyboardEvent)br.ReadInt32();
                            KeyboardEvent eventData = new KeyboardEvent();
                            eventData.vKeyCode = br.ReadUInt32();
                            eventData.scanCode = br.ReadUInt32();
                            eventData.Flags = br.ReadUInt32();
                            eventData.Time = 0;
                            eventData.dwExtraInfo = WinApi.GetMessageExtraInfo();
                            loadedEvents[eventIndex] = new MacroEvent_Keyboard(kbEvent, eventData);
                        }

                        if(mType == MacroEventType.Mouse)
                        {
                            eMouseButton mButton = (eMouseButton)br.ReadInt32();
                            MouseEvent mEvent = new MouseEvent();
                            mEvent.mouseData = br.ReadUInt32();
                            mEvent.Location = new mPoint();
                            mEvent.Location.X = br.ReadInt32();
                            mEvent.Location.Y = br.ReadInt32();
                            mEvent.Flags = br.ReadUInt32();
                            loadedEvents[eventIndex] = new MacroEvent_Mouse(mEvent, mButton);
                        }
                        eventIndex++;
                    }
                }
                ClearCurrent();
                foreach (IMacroEvent lEvent in loadedEvents)
                    AddEvent(lEvent);
                MessageBox.Show("Loaded successfully");
            }
            catch
            {
                MessageBox.Show("Failed to load macro.");
            }
        }