private void ChangeDownloadPath(string targetPath) { if (!Directory.Exists(targetPath)) { Directory.CreateDirectory(targetPath); } string currentPath = AutoItX.ControlGetText("[TITLE:Save As; CLASS:#32770]", "", "[CLASS:ToolbarWindow32; INSTANCE:4]"); if (!currentPath.Contains(targetPath)) { AutoItX.WinActivate("[TITLE:Save As; CLASS:#32770]", ""); IntPtr w = AutoItX.WinGetHandle("[TITLE:Save As; CLASS:#32770]", ""); IntPtr c = AutoItX.ControlGetHandle(w, "[CLASS:ToolbarWindow32; INSTANCE:4]"); Rectangle mainWindowPosition = AutoItX.WinGetPos(w); Rectangle refElementPosition = AutoItX.ControlGetPos(w, c); int startX = mainWindowPosition.X + refElementPosition.X + refElementPosition.Width - 10; int startY = mainWindowPosition.Y + refElementPosition.Y + refElementPosition.Height / 2; AutoItX.MouseMove(startX + 15, startY + 25); AutoItX.MouseClick("LEFT", startX + 15, startY + 25); AutoItX.Send("{BACKSPACE}"); AutoItX.AutoItSetOption("SendKeyDelay", GetRandomDelay(50)); AutoItX.Send(targetPath); Thread.Sleep(TimeSpan.FromSeconds(1)); AutoItX.Send("{ENTER}"); } }
/// <summary> /// Runs the air game proc. /// </summary> /// <param name="gameTitle">The game title.</param> /// <exception cref="System.TimeoutException"></exception> private void RunAirGameProc(string gameTitle) { // (should not happen under normal circumstances // but, in case something abnormal occurs) Kill // Air Game App window if it is active before we // launch new Air Game exe instance AutoItX.AutoItSetOption("WinTitleMatchMode", 3); if (0 != AutoItX.WinExists(AirGameWindowTitle)) { AutoItX.WinKill(AirGameWindowTitle); } // Start Air Game exe as separate process _airGameProcess = new Process { StartInfo = { FileName = GameDirectoryPath + @"\" + gameTitle + @"\" + gameTitle + @".exe" } }; _airGameProcess.Start(); // if Air Game has not exited after max wait time, we assume // something went wrong if (!_airGameProcess.WaitForExit(AirProcWaitTimeoutMillis)) { Recorder.PowerOff(); _airGameProcess.Kill(); var errMsg = $"Exceeded wait time ({AirProcWaitTimeoutMillis/1000/60} minutes) for Air Game execution to complete"; throw new TimeoutException(errMsg); } }
/// <summary> /// 关闭游戏异常 /// </summary> /// <returns></returns> internal static bool CloseCrashReport() { AutoItX.AutoItSetOption("WinTitleMatchMode", 3); bool result = false; var crashReport = "Crash Report"; var fatalError = "Fatal error"; // 游戏崩溃 if (AutoItX.WinExists(crashReport) == 1) { //正常的关闭窗口(WinClose) 强行关闭窗口(WinKill) AutoItX.WinClose(crashReport); //等待窗口被关闭 AutoItX.WinWaitClose(crashReport); result = true; } // 游戏致命错误 if (AutoItX.WinExists(fatalError) == 1) { AutoItX.WinClose(fatalError); AutoItX.WinWaitClose(fatalError); result = true; } return(result); }
private void EnterTextBox(IntPtr mainWindow, IntPtr textBox, string value) { ClickToFocus(mainWindow, textBox); AutoItX.AutoItSetOption("SendKeyDelay", GetRandomDelay(100)); AutoItX.ControlSetText(mainWindow, textBox, value); AutoItX.Sleep(GetRandomDelay(1000)); }
private void ClickElement(int startX, int startY, int offsetX, int offsetY) { int elementPossitionX = startX + offsetX; int elementPossitionY = startY + offsetY; AutoItX.AutoItSetOption("SendKeyDelay", GetRandomDelay(100)); AutoItX.MouseClick("LEFT", elementPossitionX, elementPossitionY); AutoItX.Sleep(GetRandomDelay(1000)); }
private void EnterTextBox(IntPtr mainWindow, IntPtr textBox, string value) { if (AutoItX.ControlFocus(mainWindow, textBox) == AutoItXSuccess) { Thread.Sleep(GetRandomDelay(100)); AutoItX.AutoItSetOption("SendKeyDelay", GetRandomDelay(100)); AutoItX.ControlSetText(mainWindow, textBox, value); Thread.Sleep(GetRandomDelay(100)); } }
private void EnterPinBox(IntPtr mainWindow, IntPtr textBox, string value) { if (AutoItX.ControlFocus(mainWindow, textBox) == AutoItXSuccess) { ClickToFocus(mainWindow, textBox); AutoItX.AutoItSetOption("SendKeyDelay", GetRandomDelay(100)); AutoItX.Send(value); AutoItX.Sleep(GetRandomDelay(1000)); } }
/// <summary> /// 窗口标题匹配是否存在 /// </summary> /// <returns></returns> internal static bool WindowExists() { //更改窗口函数在执行搜索操作时的标题匹配模式. //1 = 只匹配标题的前面部分(默认) //2 = 标题的任意子串皆可匹配 //3 = 完全匹配标题 //4 = 高级模式,详情请查看 窗口标题与文本(高级) //-1 到 - 4 = 强制小写匹配. AutoItX.AutoItSetOption("WinTitleMatchMode", 3); return(AutoItX.WinExists("Gwent") == 1 ? true : false); }
private void EnterOtpBox(IntPtr mainWindow, IntPtr textBox, string value) { if (AutoItX.ControlFocus(mainWindow, textBox) == AutoItXSuccess) { ClickToFocus(mainWindow, textBox); AutoItX.AutoItSetOption("SendKeyDelay", GetRandomDelay(100)); SimulateKey.SetForegroundWindow(textBox); SimulateKey.ClearText(textBox); SimulateKey.SendText(textBox, value); AutoItX.Sleep(GetRandomDelay(1000)); } }
/// <summary> /// 关闭游戏进程 /// </summary> /// <returns></returns> internal static bool CloseProcess() { AutoItX.AutoItSetOption("WinTitleMatchMode", 3); bool result = AutoItX.WinClose("Gwent") == 1 ? true : false; if (result) { AutoItX.WinWaitClose("Gwent"); } Thread.Sleep(10000); return(result); }
public static bool SendKeys(ushort iterations, string keyCombination, string window, IProgress <int> progress, ushort keyDelay = 150) { try { if (AutoItX.WinWaitActive(window, timeout: 15) == 1) { if (MessageBox.Show(ActiveWindow.Active, "Do you confirm that this is desired application instance and that cursor is set appropriately?", "Confirmation Required", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return(false); } Point mouseLocation = AutoItX.MouseGetPos(); int x = mouseLocation.X; int y = mouseLocation.Y; AutoItX.AutoItSetOption("SendKeyDelay", keyDelay); AutoItX.Sleep(3000); for (int i = 1; i <= iterations; i++) { mouseLocation = AutoItX.MouseGetPos(); if (mouseLocation.X - x < 150 && mouseLocation.X - x > -150 && mouseLocation.Y - y < 150 && mouseLocation.Y - y > -150) { progress.Report(i); AutoItX.Send(keyCombination); } else { MessageBox.Show(ActiveWindow.Active, "Significant mouse move detected. Breaking execution.", "Execution Stopped", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } } return(true); } MessageBox.Show("Application (" + window + ") window has not been activated within 15 seconds.", "Execution Stopped", MessageBoxButtons.OK, MessageBoxIcon.Stop); return(false); } finally { } }
/// <summary> /// Powers On the Video Recorder. /// </summary> public void PowerOn() { lock (_syncObj) { _isRecording = false; AutoItX.AutoItSetOption("WinTitleMatchMode", 2); if (0 == AutoItX.WinExists(ObsWindowTitle)) { AutoItX.Run(GameShareRootDirectory + @"\obsRun.bat", GameShareRootDirectory); } AutoItX.WinActivate(ObsWindowTitle); } }
/// <summary> /// To verify any File if it is PDF or not /// </summary> public void VerifyPDFfile(string pdfTitle) { AutoItX.WinActivate("Adobe Acrobat Reader DC"); AutoItX.AutoItSetOption("WinTitleMatchMode", 2); if (AutoItX.WinExists(pdfTitle + ".pdf - Adobe Acrobat Reader DC", "").ToString() == "1") { AutoItX.Send("{Enter}"); //PDF exist } else { Assert.Fail("Fail to convert into pdf. PDF file is not opened."); } }
private void WaitForWindow(string windowID, int waitTime = 10, string windowText = "") { AutoItX.AutoItSetOption("WinTitleMatchMode", 3); var handle = AutoItX.WinWaitActive(windowID, windowText, waitTime); //if ((windowID != termsandConditonWindowTitle) || (windowID != certificationWindowTitle)) //Dont show errorpopup if there is no terms and condition popup if ((windowID != termsandConditonWindowTitle) && (windowID != certificationWindowTitle)) //Dont show errorpopup if there is no terms and condition popup { //do nothing if (AutoItX.WinExists(windowID) == 0) //Autoit return 1 for success and 0 for failure { ShowErrorPopup($"'{windowID}' : unable to locate this window title"); } } }
/// <summary> /// Ожидает валидного состояния игры 30 секунд. Если состояние валидно создает новый объект. /// Если 30 секунд состояние игры не валидно выбрасывает исключение. /// 等待有效的游戏状态30秒钟。 如果游戏状态在30秒内未有效抛出异常。状态有效,则创建一个新对象。 /// </summary> /// <param name="stateChecker"> IGwentStateChecker 实现类</param> /// <param name="waitingService">Класс инкапсулирующий метод ожидания</param> /// <param name="inputEmul">Класс эмуляции устройств ввода</param> public PageObject( IGwentStateChecker stateChecker, IWaitingService waitingService, IInputDeviceEmulator inputEmulator) { this.stateChecker = stateChecker; this.waitingService = waitingService; this.inputEmulator = inputEmulator; WaitingGameReadiness(); AutoItX.AutoItSetOption("MouseCoordMode", 2); AutoItX.AutoItSetOption("PixelCoordMode", 2); lastTimeCreationNewPage = DateTime.Now.TimeOfDay; }
public AutoitInputDeviceEmulator() { //调整Autoit各种函数/参数的运作方式. //设置用于鼠标函数的坐标参照,可以是绝对位置也可以是相对当前激活窗口的坐标位置. //0 = 相对激活窗口的坐标 //1 = 屏幕的绝对位置(默认) //2 = 相对激活窗口客户区的坐标 AutoItX.AutoItSetOption("MouseCoordMode", 2); //设置用于象素函数的坐标参照,可以是绝对位置也可以是相对当前激活窗口的坐标位置. //0 = 相对激活窗口的坐标 //1 = 屏幕的绝对位置(默认) //2 = 相对激活窗口客户区的坐标 AutoItX.AutoItSetOption("PixelCoordMode", 2); }
/// <summary> /// Получаем не видимый текст с окна /// </summary> /// <param name="namewinactive">Наименование заголовка окна</param> /// <returns></returns> public static string HidenTextReturn(string namewinactive) { string parametr = null; AutoItX.AutoItSetOption("WinDetectHiddenText", 1); while (true) { if (String.IsNullOrWhiteSpace(parametr)) { parametr = AutoItX.WinGetText(namewinactive, ""); } else { break; } } return(parametr); }
/// <summary> /// Stops the recording. /// </summary> public void StopRecording() { Logger.Debug("Stop Recording"); lock (_syncObj) { if (!_isRecording) { return; } _isRecording = false; AutoItX.AutoItSetOption("WinTitleMatchMode", 2); AutoItX.WinActivate(ObsWindowTitle); AutoItX.ControlClick(ObsWindowTitle, "", ObsStartStopButtonId, "LEFT", 1, ObsStartStopButtonXPos, ObsStartStopButtonYPos); } }
/// <summary> /// Powers Off the Video Recorder. /// </summary> public void PowerOff() { Logger.Debug("Exit"); lock (_syncObj) { if (_isRecording) { StopRecording(); } AutoItX.AutoItSetOption("WinTitleMatchMode", 2); if (0 == AutoItX.WinExists(ObsWindowTitle)) { return; } AutoItX.WinActivate(ObsWindowTitle); AutoItX.ControlClick(ObsWindowTitle, "", ObsExitButtonId, "LEFT", 1, ObsExitButtonXPos, ObsExitButtonYPos); } }
private void button1_Click(object sender, RoutedEventArgs e) { string lang = "00000419"; int ret = LoadKeyboardLayout(lang, 1); PostMessage(GetForegroundWindow(), 0x50, 1, ret); var exePath = AppDomain.CurrentDomain.BaseDirectory; object path = Path.Combine(exePath, "parse_status.exe"); string url = text_url.Text; if (url.IndexOf("m.vk") == -1) { int i = url.IndexOf("vk.com"); url = url.Insert(i, "m."); } AutoItX.ClipPut(url); Process.Start("IExplore.exe"); AutoItX.AutoItSetOption("WinTitleMatchMode", 2); AutoItX.WinWaitActive("Internet Explorer"); AutoItX.Send(url + "{ENTER}"); Process.Start(@"" + path); AutoItX.WinWaitActive("MainWindow"); lb_status.Content = AutoItX.ClipGet(); }
/// <summary> /// 启动游戏进程 /// </summary> /// <returns></returns> internal static bool StartProcess() { AutoItX.AutoItSetOption("WinTitleMatchMode", 3); // 1971477531 国际服 1781625612 国服 // 程序路径 var programPath = Registry.GetValue( @"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\GOG.com\Games\1971477531", "exe", null); // 工作目录 var workingDir = Registry.GetValue( @"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\GOG.com\Games\1971477531", "workingDir", null); if (programPath.ToString() == string.Empty) { programPath = ConfigurationManager.AppSettings.Get("GamePath"); } do { CloseCrashReport(); AutoItX.Run(programPath.ToString(), workingDir.ToString()); // 等待窗口出现 AutoItX.WinWait("Gwent"); CloseCrashReport(); // 等待窗口被激活 AutoItX.WinActivate("Gwent"); } while (!WindowExists()); // 重置最新页面创建时间差(间隔) PageObject.ResetLastCreationTimePage(); return(WindowExists()); }
public void GoBack(int timePress) { AutoItX.AutoItSetOption("SendKeyDownDelay", timePress); AutoItX.Send("s"); AutoItX.AutoItSetOption("SendKeyDownDelay", 5); }
public void TurnRight(int timePress) { AutoItX.AutoItSetOption("SendKeyDownDelay", timePress); AutoItX.Send("c"); AutoItX.AutoItSetOption("SendKeyDownDelay", 5); }
public void GoForward(int timePress) { AutoItX.AutoItSetOption("SendKeyDownDelay", timePress); AutoItX.Send("w"); AutoItX.AutoItSetOption("SendKeyDownDelay", 5); }
public void AutoUseTool() { AutoItX.AutoItSetOption("SendKeyDownDelay", 200); AutoItX.Send("b"); AutoItX.AutoItSetOption("SendKeyDownDelay", 5); }
public void NextTarget() { AutoItX.AutoItSetOption("SendKeyDownDelay", 200); AutoItX.Send("0"); AutoItX.AutoItSetOption("SendKeyDownDelay", 5); }
public static int AutoItSetOption(string strOption, int nValue) { return(AutoItX.AutoItSetOption(strOption, nValue)); }
public int AutoItSetOption(string option, int optionValue) { return(AutoItX.AutoItSetOption(option, optionValue)); }
//static AutoIt.AutoItX _autoIT = new AutoIt.AutoItX(); static public void init() { AutoItX.AutoItSetOption("SendKeyDelay", 0); }
private static void FillUpTransferForm(IntPtr inputMainPanel) { var toAccountNumber = "6214837694277025"; var toAccountName = "吕文斌"; //var fromAccountNumber = ""; //var fromAccountName = ""; var transactionReferenceId = "12345678912"; var transactionReference = "test Remarks"; var amount = "1"; //Click Transger if (AutoItX.WinActivate(_mainForm) != 1) { return; } WaitForTransferPage(); var inputMainPanelPosition = AutoItX.ControlGetPos(_mainForm, inputMainPanel); var elemementPositionX = _windowsPosition.X + inputMainPanelPosition.X; var elemementPositionY = _windowsPosition.Y + inputMainPanelPosition.Y; //Account Name AutoItX.WinActivate(_mainForm); AutoItX.AutoItSetOption("SendKeyDelay", GetRandomDelay(100)); var txttoAccount = AutoItX.ControlGetHandle(_mainForm, "[CLASS:Edit; INSTANCE:1]"); AutoItX.ControlSetText(_mainForm, txttoAccount, toAccountName); AutoItX.MouseClick("LEFT", elemementPositionX + 200, elemementPositionY + 35); Thread.Sleep(GetRandomDelay(1000)); //Account Number AutoItX.WinActivate(_mainForm); AutoItX.AutoItSetOption("SendKeyDelay", GetRandomDelay(100)); AutoItX.MouseClick("LEFT", elemementPositionX + 200, elemementPositionY + 75); AutoItX.Send(toAccountNumber); Thread.Sleep(GetRandomDelay(1000)); //Bank AutoItX.WinActivate(_mainForm); AutoItX.AutoItSetOption("SendKeyDelay", GetRandomDelay(100)); AutoItX.MouseClick("LEFT", elemementPositionX + 200, elemementPositionY + 120); Thread.Sleep(GetRandomDelay(1000)); //Amount AutoItX.WinActivate(_mainForm); AutoItX.AutoItSetOption("SendKeyDelay", GetRandomDelay(100)); AutoItX.MouseClick("LEFT", elemementPositionX + 200, elemementPositionY + 230); AutoItX.Send(amount); Thread.Sleep(GetRandomDelay(1000)); //transaction Remarks AutoItX.WinActivate(_mainForm); AutoItX.AutoItSetOption("SendKeyDelay", GetRandomDelay(100)); AutoItX.MouseClick("LEFT", elemementPositionX + 200, elemementPositionY + 285); AutoItX.Send(transactionReference); Thread.Sleep(GetRandomDelay(1000)); //transaction ID AutoItX.WinActivate(_mainForm); AutoItX.AutoItSetOption("SendKeyDelay", GetRandomDelay(100)); AutoItX.MouseClick("LEFT", elemementPositionX + 200, elemementPositionY + 335); AutoItX.Send(transactionReferenceId); Thread.Sleep(GetRandomDelay(1000)); AutoItX.WinActivate(_mainForm); AutoItX.AutoItSetOption("SendKeyDelay", GetRandomDelay(100)); AutoItX.MouseClick("LEFT", elemementPositionX + 200, elemementPositionY + 380); Thread.Sleep(GetRandomDelay(1000)); if (ConfirmationMessageFindByClassName("TPbBaseMsgForm", new Tuple <int, int>(285, 180))) { Console.WriteLine("Error FillUpTransferForm"); } }