private void recHotkey_HotkeyPressed(object sender, EventArgs e) { if (state == MacroState.STOPPED) { if (llhook) { llmacro.Clear(); } else { macro.Clear(); } state = MacroState.RECORDING; lastTickCount = 0; timer1.Enabled = true; } else if (state == MacroState.PLAYING) { // do nothing } else if (state == MacroState.RECORDING) { lastTickCount = Environment.TickCount; state = MacroState.RECORDING_DELAY; RemoveEvent(recHotkey.KeyCode); } else if (state == MacroState.RECORDING_DELAY) { state = MacroState.RECORDING; lastTickCount = Environment.TickCount - lastTickCount; RemoveEvent(recHotkey.KeyCode); } UpdateIcons(); }
JournalMessage play_GetNextJournalMessage(ref int timestamp) { if (index >= macro.Count) { index = -1; timestamp = Environment.TickCount + 500; System.Diagnostics.Debug.WriteLine("NearEND"); return(null); } else if (index == -1) { state = MacroState.STOPPED; UpdateIcons(); System.Diagnostics.Debug.WriteLine("END"); return(null); } else { int ltc = lastTickCount; timestamp = ltc + macro[index].Time; lastTickCount = timestamp; System.Diagnostics.Debug.WriteLine("REAL: " + timestamp + " " + Environment.TickCount + " " + macro[index]); index++; return(macro[index - 1]); } }
private static void Macros(MacroState state, IBMDSwitcher switcher) { var pool = switcher as IBMDSwitcherMacroPool; pool.GetMaxCount(out uint count); state.Pool = Enumerable.Range(0, (int)count).Select(i => { pool.IsValid((uint)i, out int valid); pool.HasUnsupportedOps((uint)i, out int unsupported); pool.GetName((uint)i, out string name); pool.GetDescription((uint)i, out string description); return(new MacroState.ItemState { IsUsed = valid != 0, HasUnsupportedOps = unsupported != 0, Name = name, Description = description }); }).ToList(); var control = switcher as IBMDSwitcherMacroControl; control.GetRunStatus(out _BMDSwitcherMacroRunStatus status, out int loop, out uint index); switch (status) { case _BMDSwitcherMacroRunStatus.bmdSwitcherMacroRunStatusIdle: state.RunStatus.RunStatus = MacroState.MacroRunStatus.Idle; break; case _BMDSwitcherMacroRunStatus.bmdSwitcherMacroRunStatusRunning: state.RunStatus.RunStatus = MacroState.MacroRunStatus.Running; break; case _BMDSwitcherMacroRunStatus.bmdSwitcherMacroRunStatusWaitingForUser: state.RunStatus.RunStatus = MacroState.MacroRunStatus.UserWait; break; default: throw new ArgumentOutOfRangeException(nameof(status), status, null); } state.RunStatus.Loop = loop != 0; state.RunStatus.RunIndex = index; control.GetRecordStatus(out _BMDSwitcherMacroRecordStatus recStatus, out uint recIndex); state.RecordStatus.IsRecording = recStatus == _BMDSwitcherMacroRecordStatus.bmdSwitcherMacroRecordStatusRecording; state.RecordStatus.RecordIndex = recIndex; }
private void playHotkey_HotkeyPressed(object sender, EventArgs e) { if (state == MacroState.STOPPED) { lastTickCount = Environment.TickCount; state = MacroState.PLAYING; if (llhook) { llindex = 0; if (bi) { iblock = new InputBlocker(); } playTimer.Interval = 1; playTimer.Enabled = true; } else { index = 0; play = new JournalPlaybackHook(); play.GetNextJournalMessage += new JournalPlaybackHook.JournalQuery(play_GetNextJournalMessage); play.StartHook(); } } else if (state == MacroState.PLAYING) { // do nothing } else { if (llhook) { kbd.Unhook(); mouse.Unhook(); } else { rec.Unhook(); } state = MacroState.STOPPED; RemoveEvent(playHotkey.KeyCode); } UpdateIcons(); }
private void playTimer_Tick(object sender, EventArgs e) { while (llindex < llmacro.Count) { int ltc = lastTickCount; int timestamp = ltc + llmacro[llindex].Time; if (timestamp > Environment.TickCount) { playTimer.Interval = Math.Max(1, timestamp - Environment.TickCount - 5); return; } llmacro[llindex].ReplayEvent(); lastTickCount = timestamp; llindex++; } llindex = -1; state = MacroState.STOPPED; if (bi) { iblock.Dispose(); } UpdateIcons(); playTimer.Enabled = false; }
private void playHotkey_HotkeyPressed(object sender, EventArgs e) { if (state == MacroState.STOPPED) { lastTickCount = Environment.TickCount; state = MacroState.PLAYING; if (llhook) { llindex = 0; if(bi) iblock = new InputBlocker(); playTimer.Interval = 1; playTimer.Enabled = true; } else { index = 0; play = new JournalPlaybackHook(); play.GetNextJournalMessage += new JournalPlaybackHook.JournalQuery(play_GetNextJournalMessage); play.StartHook(); } } else if (state == MacroState.PLAYING) { // do nothing } else { if (llhook) { kbd.Unhook(); mouse.Unhook(); } else { rec.Unhook(); } state = MacroState.STOPPED; RemoveEvent(playHotkey.KeyCode); } UpdateIcons(); }
private void recHotkey_HotkeyPressed(object sender, EventArgs e) { if (state == MacroState.STOPPED) { if (llhook) llmacro.Clear(); else macro.Clear(); state = MacroState.RECORDING; lastTickCount = 0; timer1.Enabled = true; } else if (state == MacroState.PLAYING) { // do nothing } else if (state == MacroState.RECORDING) { lastTickCount = Environment.TickCount; state = MacroState.RECORDING_DELAY; RemoveEvent(recHotkey.KeyCode); } else if (state == MacroState.RECORDING_DELAY) { state = MacroState.RECORDING; lastTickCount = Environment.TickCount - lastTickCount; RemoveEvent(recHotkey.KeyCode); } UpdateIcons(); }
JournalMessage play_GetNextJournalMessage(ref int timestamp) { if (index >= macro.Count) { index = -1; timestamp = Environment.TickCount + 500; System.Diagnostics.Debug.WriteLine("NearEND"); return null; } else if (index == -1) { state = MacroState.STOPPED; UpdateIcons(); System.Diagnostics.Debug.WriteLine("END"); return null; } else { int ltc = lastTickCount; timestamp = ltc + macro[index].Time; lastTickCount = timestamp; System.Diagnostics.Debug.WriteLine("REAL: " + timestamp + " " + Environment.TickCount + " " + macro[index]); index++; return macro[index - 1]; } }
private void playTimer_Tick(object sender, EventArgs e) { while (llindex < llmacro.Count) { int ltc = lastTickCount; int timestamp = ltc + llmacro[llindex].Time; if (timestamp > Environment.TickCount) { playTimer.Interval = Math.Max(1, timestamp - Environment.TickCount - 5); return; } llmacro[llindex].ReplayEvent(); lastTickCount = timestamp; llindex++; } llindex = -1; state = MacroState.STOPPED; if (bi) iblock.Dispose(); UpdateIcons(); playTimer.Enabled = false; }
void Fail(object message = null, int conditionIndex = 0) { // break a macro MacroState macroState = Far.Api.MacroState; if (macroState == MacroState.Executing || macroState == MacroState.ExecutingCommon) { Far.Api.UI.Break(); } // get the message if (message == null) { ScriptBlock messageScript = Cast <ScriptBlock> .From(Message); if (messageScript != null) { try { Message = messageScript.InvokeReturnAsIs(); } catch (RuntimeException ex) { Message = "Error in the message script: " + ex.Message; Title = null; } } } else { Message = message; } // body //! use "\n" as the separator, not "\r": PositionMessage starts with "\n". string body = Message == null ? "Assertion failed" : Message.ToString(); if (IsError) { if (conditionIndex > 0) { body = string.Concat(body, (body.Length > 0 ? "\n" : string.Empty), "Condition #", conditionIndex + 1); } //! Trim() for PowerShell 2.0 body = string.Concat(body, (body.Length > 0 ? "\n" : string.Empty), MyInvocation.PositionMessage.Trim()); } // buttons string[] buttons; if (!IsError) { buttons = new string[] { BtnBreak, BtnThrow } } ; else if (string.IsNullOrEmpty(MyInvocation.ScriptName)) { buttons = new string[] { BtnBreak, BtnThrow, BtnDebug } } ; else { buttons = new string[] { BtnBreak, BtnThrow, BtnDebug, BtnEdit } }; // prompt for (; ;) { int result = Far.Api.Message( body, Title ?? MyName, IsError ? (MessageOptions.Warning | MessageOptions.LeftAligned) : MessageOptions.None, buttons); if (result < 0) { continue; } switch (buttons[result]) { case BtnBreak: { throw new PipelineStoppedException(); } case BtnThrow: { throw new PSInvalidOperationException(body); } case BtnDebug: { A.InvokeCode("Set-PSBreakpoint -Variable daf01ff6-f004-43bd-b6bf-cf481e9333d3 -Mode Read"); SessionState.PSVariable.Set("daf01ff6-f004-43bd-b6bf-cf481e9333d3", null); GetVariableValue("daf01ff6-f004-43bd-b6bf-cf481e9333d3"); return; } case BtnEdit: { IEditor editor = Far.Api.CreateEditor(); editor.FileName = MyInvocation.ScriptName; editor.GoToLine(MyInvocation.ScriptLineNumber - 1); editor.Open(); goto case BtnBreak; } } } } const string BtnBreak = "&Break", BtnThrow = "&Throw", BtnDebug = "&Debug", BtnEdit = "&Edit"; }