protected override void InternalExecute(ICommandAdapter adapter) { if (Parameters.MainParameter == null) { Parameters.MainParameter = new MainParameter(); } var activateApplicationWindowCommand = new ActivateWindowCommand(); activateApplicationWindowCommand.SynchWith(this); activateApplicationWindowCommand.Execute(adapter); var simulator = new Automation.InputSimulator.InputSimulator(); if (!string.IsNullOrEmpty(Parameters.MainParameter.Value)) { simulator.Keyboard.TextEntry(Parameters.MainParameter.Value); } var field = this.ParameterValue("Field", ""); if (!string.IsNullOrEmpty(field)) { var fillFieldCommand = new FillFieldCommand(); fillFieldCommand.Parameters.Add(new Parameter(field, "", true, EndPosition)); fillFieldCommand.Execute(adapter); } Execute(simulator); }
private static void ActivateAppWindow(ICommandAdapter adapter) { try{ var activateApplicationWindowCommand = new ActivateWindowCommand(); activateApplicationWindowCommand.Execute(adapter); } catch { // ignored } }
public TaskBarElement(string fullPath) { FullPath = fullPath; Name = Path.GetFileNameWithoutExtension(FullPath); if (Path.GetExtension(fullPath) == ".exe") { ProcessIcon = Icon.ExtractAssociatedIcon(fullPath)?.ToBitmap().ToBitmapSource(); } ProcessInfo = Process.Start(fullPath); ActivateWindowCmnd = new ActivateWindowCommand(); CloseWindowCmnd = new CloseWindowCommand(); }
//build window command private static void BuildWindowCommand(IntPtr hWinEventHook, SystemEvents @event, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) { switch (@event) { case SystemEvents.EVENT_MIN: return; case SystemEvents.EVENT_MAX: return; case SystemEvents.EVENT_SYSTEM_FOREGROUND: break; case SystemEvents.MINIMIZE_END: return; case SystemEvents.MINIMIZE_START: return; default: return; } int length = GetWindowText(hwnd, _Buffer, _Buffer.Capacity); var windowName = _Buffer.ToString(); //bypass screen recorder and Cortana (Win10) which throws errors if ((windowName == "Screen Recorder") || (windowName == "Cortana")) { return; } if (length > 0) { //wait additional for window to initialize //System.Threading.Thread.Sleep(250); windowName = _Buffer.ToString(); Automation.Commands.ActivateWindowCommand activateWindowCommand = new ActivateWindowCommand { v_WindowName = windowName, v_Comment = "Generated by Screen Recorder @ " + DateTime.Now.ToString() }; generatedCommands.Add(activateWindowCommand); //detect if tracking window open location or activate windows to top left if (trackWindowOpenLocations) { GetWindowRect(hwnd, out RECT windowRect); Automation.Commands.MoveWindowCommand moveWindowCommand = new MoveWindowCommand { v_WindowName = windowName, v_XWindowPosition = windowRect.left.ToString(), v_YWindowPosition = windowRect.top.ToString(), v_Comment = "Generated by Screen Recorder @ " + DateTime.Now.ToString() }; generatedCommands.Add(moveWindowCommand); } else if (activateWindowTopLeft) { //generate command to set window position Automation.Commands.MoveWindowCommand moveWindowCommand = new MoveWindowCommand { v_WindowName = windowName, v_XWindowPosition = "0", v_YWindowPosition = "0", v_Comment = "Generated by Screen Recorder @ " + DateTime.Now.ToString() }; SetWindowPosition(hwnd, 0, 0); generatedCommands.Add(moveWindowCommand); } //if tracking window sizes is set if (trackActivatedWindowSizes) { //create rectangle from hwnd GetWindowRect(hwnd, out RECT windowRect); //do math to get height, etc var width = windowRect.right - windowRect.left; var height = windowRect.bottom - windowRect.top; //generate command to set window position Automation.Commands.ResizeWindowCommand reszWindowCommand = new ResizeWindowCommand { v_WindowName = windowName, v_XWindowSize = width.ToString(), v_YWindowSize = height.ToString(), v_Comment = "Generated by Screen Recorder @ " + DateTime.Now.ToString() }; //add to list generatedCommands.Add(reszWindowCommand); } } }
//build window command private static void BuildWindowCommand(IntPtr hWinEventHook, _systemEvents @event, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) { switch (@event) { case _systemEvents.EventMin: return; case _systemEvents.EventMax: return; case _systemEvents.EventSystemForeGround: break; case _systemEvents.MinimizeEnd: return; case _systemEvents.MinimizeStart: return; default: return; } int length = GetWindowText(hwnd, _buffer, _buffer.Capacity); var windowName = _buffer.ToString(); //bypass screen recorder and Cortana (Win10) which throws errors if ((windowName == "Screen Recorder") || (windowName == "Cortana")) { return; } if (length > 0) { //wait additional for window to initialize //System.Threading.Thread.Sleep(250); windowName = _buffer.ToString(); ActivateWindowCommand activateWindowCommand = new ActivateWindowCommand { v_WindowName = windowName, v_Comment = "Generated by Screen Recorder @ " + DateTime.Now.ToString() }; GeneratedCommands.Add(activateWindowCommand); //detect if tracking window open location or activate windows to top left if (_trackWindowOpenLocations) { User32Functions.GetWindowRect(hwnd, out Rect windowRect); MoveWindowCommand moveWindowCommand = new MoveWindowCommand { v_WindowName = windowName, v_XMousePosition = windowRect.left.ToString(), v_YMousePosition = windowRect.top.ToString(), v_Comment = "Generated by Screen Recorder @ " + DateTime.Now.ToString() }; GeneratedCommands.Add(moveWindowCommand); } else if (_activateWindowTopLeft) { //generate command to set window position MoveWindowCommand moveWindowCommand = new MoveWindowCommand { v_WindowName = windowName, v_XMousePosition = "0", v_YMousePosition = "0", v_Comment = "Generated by Screen Recorder @ " + DateTime.Now.ToString() }; User32Functions.SetWindowPosition(hwnd, 0, 0); GeneratedCommands.Add(moveWindowCommand); } //if tracking window sizes is set if (_trackActivatedWindowSizes) { //create rectangle from hwnd User32Functions.GetWindowRect(hwnd, out Rect windowRect); //do math to get height, etc var width = windowRect.right - windowRect.left; var height = windowRect.bottom - windowRect.top; //generate command to set window position ResizeWindowCommand reszWindowCommand = new ResizeWindowCommand { v_WindowName = windowName, v_XWindowSize = width.ToString(), v_YWindowSize = height.ToString(), v_Comment = "Generated by Screen Recorder @ " + DateTime.Now.ToString() }; //add to list GeneratedCommands.Add(reszWindowCommand); } } }
private void pbRecord_Click(object sender, EventArgs e) { // this.WindowState = FormWindowState.Minimized; if (!_isRecording) { _isRecording = true; SearchParameters = NewSearchParameterDataTable(); //clear all SearchParameters.Rows.Clear(); //get window name and find window _windowName = cboWindowTitle.Text; IntPtr hWnd = User32Functions.FindWindow(_windowName); if (IsRecordingSequence && _isFirstRecordClick) { _isFirstRecordClick = false; _sequenceCommandList = new List <ScriptCommand>(); frmThickAppElementRecorderSettings settingsForm = new frmThickAppElementRecorderSettings(); settingsForm.ShowDialog(); if (settingsForm.DialogResult == DialogResult.OK) { _parameterSettings = settingsForm.ParameterSettingsDT; } else { _isRecording = false; _isFirstRecordClick = true; lblDescription.Text = "Instructions: Select the target window name from the drop-down " + "list and click the record button. Once recording has started, click " + "the element in the target application that you want to capture."; //remove wait for left mouse down event GlobalHook.MouseEvent -= GlobalHook_MouseEvent; GlobalHook.KeyDownEvent -= GlobalHook_KeyDownEvent; GlobalHook.HookStopped -= GlobalHook_HookStopped; return; } ActivateWindowCommand activateWindowCommand = new ActivateWindowCommand { v_WindowName = _windowName }; _sequenceCommandList.Add(activateWindowCommand); } //check if window is found if (hWnd != IntPtr.Zero) { //set window state and move to 0,0 User32Functions.ActivateWindow(_windowName); User32Functions.SetWindowPosition(hWnd, 0, 0); //start global hook and wait for left mouse down event GlobalHook.StartEngineCancellationHook(Keys.F2); GlobalHook.HookStopped += GlobalHook_HookStopped; GlobalHook.StartElementCaptureHook(chkStopOnClick.Checked); GlobalHook.MouseEvent += GlobalHook_MouseEvent; GlobalHook.KeyDownEvent += GlobalHook_KeyDownEvent; } if (!chkStopOnClick.Checked) { lblDescription.Text = _recordingMessage; MoveFormToBottomRight(this); TopMost = true; } else { WindowState = FormWindowState.Minimized; } } else { _isRecording = false; if (!chkStopOnClick.Checked) { lblDescription.Text = "Recording has stopped. Press F2 to save and close."; } } }
//combobox events for form items #region ComboBox Events private void cboIEWindow_SelectionChangeCommitted(object sender, EventArgs e) { var shellWindows = new ShellWindows(); foreach (IWebBrowser2 shellWindow in shellWindows) { if (shellWindow.Document is HTMLDocument) { if (shellWindow.Document.Title == cboIEWindow.Text) { _ie = shellWindow.Application; var events = (HTMLDocumentEvents2_Event)_ie.Document; events.onclick += (evt) => { _searchParameters = new DataTable(); _searchParameters.Columns.Add("Enabled"); _searchParameters.Columns.Add("Property Name"); _searchParameters.Columns.Add("Property Value"); if (evt.srcElement is IHTMLElement) { IHTMLElement srcInfo = evt.srcElement; var elementProperties = srcInfo.GetType().GetProperties(); foreach (PropertyInfo prp in elementProperties) { var propIsString = prp.PropertyType == typeof(string); var propIsInt = prp.PropertyType == typeof(int); if ((propIsString || propIsInt) && !prp.Name.Contains("IHTML")) { string propName = prp.Name; string propValue = Convert.ToString(prp.GetValue(srcInfo)); _searchParameters.Rows.Add(false, propName, propValue); } } dgvSearchParameters.Invoke(new MethodInvoker(() => { dgvSearchParameters.DataSource = _searchParameters; }) ); } return(false); }; var activateWindow = new ActivateWindowCommand(); activateWindow.v_WindowName = cboIEWindow.Text + " - Internet Explorer"; activateWindow.RunCommand(null); var moveWindow = new MoveWindowCommand(); moveWindow.v_WindowName = cboIEWindow.Text + " - Internet Explorer"; moveWindow.v_XWindowPosition = "0"; moveWindow.v_YWindowPosition = "0"; moveWindow.RunCommand(null); MoveFormToBottomRight(this); TopMost = true; foreach (Form frm in Application.OpenForms) { if (frm.Name != Name) { frm.WindowState = FormWindowState.Minimized; } } } } } }