コード例 #1
0
        public RecordInstruction ReadNextInstruction()
        {
            RecordInstruction instruction = new RecordInstruction();

            if (!isWriting)
            {
                if (readStream.Position != readStream.Length)
                {
                    instruction.timing          = fileReader.ReadUInt32();
                    instruction.instructionType = fileReader.ReadByte();
                    if (instruction.instructionType == 0 || instruction.instructionType == 1)
                    {
                        instruction.keyCode  = fileReader.ReadUInt32();
                        instruction.scanCode = fileReader.ReadUInt32();
                    }
                    else if (instruction.instructionType == 6)
                    {
                        instruction.x = fileReader.ReadInt32();
                        instruction.y = fileReader.ReadInt32();
                    }
                    else if (instruction.instructionType == 11)
                    {
                        instruction.mouseData = fileReader.ReadInt32();
                    }
                }
                else
                {
                    EndOffStream(this, new EventArgs());
                }
            }
            return(instruction);
        }
コード例 #2
0
        private static void KeyDown(KBLLHOOKSTRUCT keyInfo)
        {
            Keys key = (Keys)keyInfo.vkCode;

            #region Strart & Stop Recording
            //Start recording
            if (key == Keys.F1 && Keys.Control == Control.ModifierKeys && !isRecoding)
            {
                notifyIcon.ShowBalloonTip(1000, "Recording", "Mouse and keyboard input is now being recorded", ToolTipIcon.None);
                isRecoding = true;
                recordFile = new RecordFile(Application.StartupPath + "\\Profile1.rec", true);
                recordFile.EndOffStream += new EventHandler(StopReplay);
                startTime = keyInfo.time;
                return;
            }
            //Stop recording
            else if (key == Keys.F1 && Keys.Control == Control.ModifierKeys && isRecoding)
            {
                notifyIcon.ShowBalloonTip(1000, "Stoped recording", "Input recording has now stopped", ToolTipIcon.None);
                isRecoding = false;
                startTime  = 0;
                recordFile.WriteLControlUp();
                recordFile.StopWrite();
                return;
            }
            #endregion
            #region Strart & Stop Replay
            if (!isRecoding)
            {
                //Start replay
                if (key == Keys.F1 && Keys.Shift == Control.ModifierKeys && !isReplaying)
                {
                    notifyIcon.ShowBalloonTip(1000, "Replaying", "Mouse and keyboard input is now being replayed", ToolTipIcon.None);
                    isReplaying = true;
                    recordFile.StartRead();
                    currentInstruction = recordFile.ReadNextInstruction();
                    timerReplay.Start();
                    return;
                }
                //Stop replay
                else if (key == Keys.F1 && Keys.Shift == Control.ModifierKeys && isReplaying)
                {
                    StopReplay(new object(), new EventArgs());
                    return;
                }
            }
            #endregion

            if (isRecoding)
            {
                RecordInstruction instruction = new RecordInstruction();
                instruction.instructionType = 0;
                instruction.timing          = keyInfo.time - startTime;
                instruction.keyCode         = keyInfo.vkCode;
                instruction.scanCode        = keyInfo.scanCode;
                recordFile.WriteInstruction(instruction);
            }
        }
コード例 #3
0
 private void timerReplay_Tick(EventTimerArgs e)
 {
     if (isReplaying)
     {
         while (currentInstruction.timing <= e.ElapsedMilliSeconds)
         {
             if (currentInstruction.instructionType == 0)
             {
                 MessageSender.SendKeyInput((ushort)currentInstruction.keyCode, (ushort)currentInstruction.scanCode, 0, 0);
             }
             else if (currentInstruction.instructionType == 1)
             {
                 MessageSender.SendKeyInput((ushort)currentInstruction.keyCode, (ushort)currentInstruction.scanCode, 2, 0);
             }
             else if (currentInstruction.instructionType == 2)
             {
                 MessageSender.SendLMBDown(0);
             }
             else if (currentInstruction.instructionType == 3)
             {
                 MessageSender.SendLMBUp(0);
             }
             else if (currentInstruction.instructionType == 4)
             {
                 MessageSender.SendRMBDown(0);
             }
             else if (currentInstruction.instructionType == 5)
             {
                 MessageSender.SendRMBUp(0);
             }
             else if (currentInstruction.instructionType == 6)
             {
                 MessageSender.SendMouseMove(currentInstruction.x, currentInstruction.y, 0);
             }
             else if (currentInstruction.instructionType == 7)
             {
                 MessageSender.SendXDown(0);
             }
             else if (currentInstruction.instructionType == 8)
             {
                 MessageSender.SendXUp(0);
             }
             else if (currentInstruction.instructionType == 9)
             {
                 MessageSender.SendMBDown(0);
             }
             else if (currentInstruction.instructionType == 10)
             {
                 MessageSender.SendMBUp(0);
             }
             else if (currentInstruction.instructionType == 11)
             {
                 MessageSender.SendMouseWheel(currentInstruction.mouseData, 0);
             }
             currentInstruction = recordFile.ReadNextInstruction();
         }
     }
 }
コード例 #4
0
        private static void MouseScroll(MSLLHOOKSTRUCT mouseInfo)
        {
            RecordInstruction instruction = new RecordInstruction();

            instruction.instructionType = 11;
            instruction.timing          = mouseInfo.time - startTime;
            instruction.mouseData       = mouseInfo.mouseData;
            recordFile.WriteInstruction(instruction);
        }
コード例 #5
0
 private static void MouseMBUp(MSLLHOOKSTRUCT mouseInfo)
 {
     if (isRecoding)
     {
         RecordInstruction instruction = new RecordInstruction();
         instruction.instructionType = 10;
         instruction.timing          = mouseInfo.time - startTime;
         recordFile.WriteInstruction(instruction);
     }
 }
コード例 #6
0
 private static void MouseMove(MSLLHOOKSTRUCT mouseInfo)
 {
     if (isRecoding)
     {
         RecordInstruction instruction = new RecordInstruction();
         instruction.instructionType = 6;
         instruction.timing          = mouseInfo.time - startTime;
         instruction.x         = mouseInfo.pt.x;
         instruction.y         = mouseInfo.pt.y;
         instruction.mouseData = mouseInfo.mouseData;
         recordFile.WriteInstruction(instruction);
     }
 }
コード例 #7
0
        private static void KeyUp(KBLLHOOKSTRUCT keyInfo)
        {
            Keys key = (Keys)keyInfo.vkCode;

            if (isRecoding)
            {
                RecordInstruction instruction = new RecordInstruction();
                instruction.instructionType = 1;
                instruction.timing          = keyInfo.time - startTime;
                instruction.keyCode         = keyInfo.vkCode;
                instruction.scanCode        = keyInfo.scanCode;
                recordFile.WriteInstruction(instruction);
            }
        }
コード例 #8
0
 public void WriteInstruction(RecordInstruction instruction)
 {
     if (isWriting)
     {
         fileWriter.Write(instruction.timing);
         fileWriter.Write(instruction.instructionType);
         if (instruction.instructionType == 0 || instruction.instructionType == 1)
         {
             fileWriter.Write(instruction.keyCode);
             fileWriter.Write(instruction.scanCode);
         }
         else if (instruction.instructionType == 6)
         {
             fileWriter.Write(instruction.x);
             fileWriter.Write(instruction.y);
         }
         if (instruction.instructionType == 11)
         {
             fileWriter.Write(instruction.mouseData);
         }
     }
 }