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}"); } }
static void Main(string[] args) { if (args.Length < 1) { return; } if (!int.TryParse(args[0], out var dropDown)) { return; } new Process { StartInfo = { FileName = @"C:\Windows\System32\control.exe", Arguments = "/name Microsoft.Sound /page playback" } }.Start(); AutoItX.WinWait("Sound"); var winHandle = AutoItX.WinGetHandle("Sound"); var listView = AutoItX.ControlGetHandle(winHandle, "[CLASS:SysListView32; INSTANCE:1]"); var btnSetDefault = AutoItX.ControlGetHandle(winHandle, "[CLASS:Button; INSTANCE:2]"); var btnOk = AutoItX.ControlGetHandle(winHandle, "[CLASS:Button; INSTANCE:4]"); AutoItX.ControlFocus(winHandle, listView); AutoItX.ControlSend(winHandle, listView, "{UP}"); for (var i = 0; i < dropDown; i++) { AutoItX.ControlSend(winHandle, listView, "{DOWN}"); } AutoItX.ControlClick(winHandle, btnSetDefault); AutoItX.ControlClick(winHandle, btnOk); }
static void RefreshHandles() { if (WindowHandle != IntPtr.Zero) { return; } WindowHandle = AutoItX.WinGetHandle(Title); TempHandle = AutoItX.ControlGetHandle(WindowHandle, "[CLASS:Static; INSTANCE:95]"); TintHandle = AutoItX.ControlGetHandle(WindowHandle, "[CLASS:Static; INSTANCE:96]"); ExposureHandle = AutoItX.ControlGetHandle(WindowHandle, "[CLASS:Static; INSTANCE:107]"); ContrastHandle = AutoItX.ControlGetHandle(WindowHandle, "[CLASS:Static; INSTANCE:108]"); HighlightsHandle = AutoItX.ControlGetHandle(WindowHandle, "[CLASS:Static; INSTANCE:109]"); ShadowsHandle = AutoItX.ControlGetHandle(WindowHandle, "[CLASS:Static; INSTANCE:110]"); WhitesHandle = AutoItX.ControlGetHandle(WindowHandle, "[CLASS:Static; INSTANCE:111]"); BlacksHandle = AutoItX.ControlGetHandle(WindowHandle, "[CLASS:Static; INSTANCE:112]"); ClarityHandle = AutoItX.ControlGetHandle(WindowHandle, "[CLASS:Static; INSTANCE:115]"); DehazeHandle = AutoItX.ControlGetHandle(WindowHandle, "[CLASS:Static; INSTANCE:116]"); VibranceHandle = AutoItX.ControlGetHandle(WindowHandle, "[CLASS:Static; INSTANCE:117]"); SaturationHandle = AutoItX.ControlGetHandle(WindowHandle, "[CLASS:Static; INSTANCE:118]"); Actions = new IntPtr[] { TempHandle, TintHandle, ExposureHandle, ContrastHandle, HighlightsHandle, ShadowsHandle, WhitesHandle, BlacksHandle, ClarityHandle, DehazeHandle, VibranceHandle, SaturationHandle }; }
private void FillOtp(IntPtr mainFormWindow, RobotContext context) { ClickButton(mainFormWindow, 550, 410); // click '获取短信验证码' button int warningHappen1 = AutoItX.WinWaitActive("[CLASS:TPbBaseMsgForm]", "选择通过短信方式获取验证码", 5); if (warningHappen1 == AutoItXSuccess) { IntPtr warningPopWin1 = AutoItX.WinGetHandle("[CLASS:TPbBaseMsgForm]", "选择通过短信方式获取验证码"); ClickButton(warningPopWin1, 250, 170); } int warningHappen2 = AutoItX.WinWaitActive("[CLASS:TPbBaseMsgForm]", "通过短信方式获取验证码的请求提交成功", 10); if (warningHappen2 == AutoItXSuccess) { IntPtr warningPopWin2 = AutoItX.WinGetHandle("[CLASS:TPbBaseMsgForm]", "通过短信方式获取验证码的请求提交成功"); ClickButton(warningPopWin2, 300, 160); } // wait to get OTP context.Otp = "6543210"; IntPtr textOtpBox = AutoItX.ControlGetHandle(mainFormWindow, "[CLASS:TCMBEdit; INSTANCE:1]"); EnterOtpBox(mainFormWindow, textOtpBox, context.Otp); ClickButton(mainFormWindow, 420, 610); // click 'Next' button Thread.Sleep(TimeSpan.FromSeconds(5)); }
private RobotResult DoLogIn(RobotContext context) { try { IntPtr loginFormWindow = AutoItX.WinGetHandle(LoginFormTitle); IntPtr textPassBox = AutoItX.ControlGetHandle(loginFormWindow, "[CLASS:TCMBStyleEdit72]"); EnterPinBox(loginFormWindow, textPassBox, context.LoginPassword); ClickButton(loginFormWindow, 200, 400); int warningHappen1 = AutoItX.WinWaitActive("[CLASS:TPbBaseMsgForm]", "", 10); //login password validate if (warningHappen1 == AutoItXSuccess) { string errorText = AutoItX.WinGetText("[CLASS:TPbBaseMsgForm]"); RobotCMB738Utils.SaveErrorShot(context.MidasTransactionId); AutoItX.WinClose("[CLASS:TPbBaseMsgForm]"); return(RobotResult.Build(context, RobotStatus.ERROR, $"Login Failed, Error<{errorText.Trim()}>")); } RobotCMB738Utils.UntilWinActive(context.MidasTransactionId, MainWindowTitle, MainWindowText); Thread.Sleep(TimeSpan.FromSeconds(2)); // sleep wait for [CLASS:Internet Explorer_Server] load done return(RobotResult.Build(context, RobotStatus.SUCCESS, "Login Success, Awesome!")); } catch (Exception e) { return(RobotResult.Build(context, RobotStatus.ERROR, e.Message)); } }
private RobotResult DoLogIn(RobotContext context) { try { IntPtr loginFormWindow = AutoItX.WinGetHandle(LoginFormTitle); IntPtr textPassBox = AutoItX.ControlGetHandle(loginFormWindow, "[CLASS:TCMBStyleEdit72]"); EnterLoginBox(loginFormWindow, textPassBox, context.LoginPassword); ClickButton(loginFormWindow, textPassBox, 70, 70); int warningHappen1 = AutoItX.WinWaitActive("[CLASS:TPbBaseMsgForm]", "", 10); //login password validate if (warningHappen1 == AutoItXSuccess) { string errorText = AutoItX.WinGetText("[CLASS:TPbBaseMsgForm]"); AutoItX.WinClose("[CLASS:TPbBaseMsgForm]"); return(RobotResult.Build(context, RobotStatus.ERROR, $"Login Failed, Error<{errorText.Trim()}>")); } WaitUtils.UntilWinActive(MainWindowTitle, MainWindowText); return(RobotResult.Build(context, RobotStatus.SUCCESS, "Login Success, Awesome!")); } catch (Exception e) { return(RobotResult.Build(context, RobotStatus.ERROR, e.Message)); } }
static void Login(string account, string password) { string title = "中信证券金融终端"; int handle = AutoItX.WinWait(title, "", 10); if (handle == 0) { throw new InvalidOperationException("failed to find login window"); } IntPtr hwnd = AutoItX.WinGetHandle(title, ""); AutoItX.WinActivate(hwnd); IntPtr hwndAccount = AutoItX.ControlGetHandle(hwnd, "[CLASSNN:SafeEdit1]"); IntPtr hwndPassword = AutoItX.ControlGetHandle(hwnd, "[CLASSNN:SafeEdit2]"); AutoItX.ControlSetText(hwnd, hwndAccount, account); AutoItX.ControlSetText(hwnd, hwndPassword, password); AutoItX.Sleep(2000); // wait 2s AutoItX.Send("{ENTER}"); }
static void DownloadQuote() { string title = "盘后数据下载"; int handle = AutoItX.WinWait(title, "", 10); if (handle == 0) { throw new InvalidOperationException("failed to find dialog for downloading quote"); } IntPtr hwnd = AutoItX.WinGetHandle(title, ""); AutoItX.WinActivate(hwnd); // select the "日线和实时行情数据" checkbox AutoItX.Send("{SPACE}"); // click the download button IntPtr buttonDownload = AutoItX.ControlGetHandle(hwnd, "[CLASSNN:Button9]"); AutoItX.ControlClick(hwnd, buttonDownload); AutoItX.Sleep(2000); // wait until the close button is enabled. IntPtr buttonClose = AutoItX.ControlGetHandle(hwnd, "[CLASSNN:Button10]"); while (AutoItX.ControlCommand(hwnd, buttonClose, "IsEnabled", "") == "0") { AutoItX.Sleep(1000); } AutoItX.ControlClick(hwnd, buttonClose); }
static void AdvancedExport() { string title = "高级导出"; int handle = AutoItX.WinWait(title, "", 10); if (handle == 0) { throw new InvalidOperationException("failed to find dialog for advance data exporting"); } IntPtr hwnd = AutoItX.WinGetHandle(title, ""); AutoItX.WinActivate(hwnd); IntPtr buttonAddObject = AutoItX.ControlGetHandle(hwnd, "[CLASSNN:Button5]"); IntPtr buttonBeginExport = AutoItX.ControlGetHandle(hwnd, "[CLASSNN:Button7]"); IntPtr buttonClose = AutoItX.ControlGetHandle(hwnd, "[CLASSNN:Button8]"); IntPtr comboBoxRight = AutoItX.ControlGetHandle(hwnd, "[CLASSNN:ComboBox3]"); IntPtr buttonGenerateHeader = AutoItX.ControlGetHandle(hwnd, "[CLASSNN:Button4]"); AutoItX.ControlCommand(hwnd, buttonGenerateHeader, "Check", ""); AutoItX.ControlCommand(hwnd, comboBoxRight, "SelectString", "前复权"); AutoItX.Sleep(2000); AutoItX.ControlClick(hwnd, buttonClose); }
private void FillInterBankTransInfo(IntPtr mainFormWindow, RobotContext context) { IntPtr textToAccountName = AutoItX.ControlGetHandle(mainFormWindow, "[CLASS:TCMBStyleEdit; INSTANCE:1]"); EnterTextBox(mainFormWindow, textToAccountName, context.ToAccountName); IntPtr textToAccountNumber = AutoItX.ControlGetHandle(mainFormWindow, "[CLASS:TCMBStyleEdit; INSTANCE:2]"); EnterTextBox(mainFormWindow, textToAccountNumber, context.ToAccountNumber); IntPtr transferTypeImmediate = AutoItX.ControlGetHandle(mainFormWindow, "[CLASS:TCMBStyleRadioButton; INSTANCE:1]"); //immediate AutoItX.ControlClick(mainFormWindow, transferTypeImmediate); Thread.Sleep(GetRandomDelay(100)); IntPtr searchComboBoxToBankName = AutoItX.ControlGetHandle(mainFormWindow, "[CLASS:TCMBSearchComboBox; INSTANCE:1]"); SearchAndSelectComboBox(mainFormWindow, searchComboBoxToBankName, context.ToBankName); IntPtr textTransferAmount = AutoItX.ControlGetHandle(mainFormWindow, "[CLASS:TCMBStyleEdit; INSTANCE:4]"); EnterTextBox(mainFormWindow, textTransferAmount, context.WithdrawAmount); IntPtr textPostscript = AutoItX.ControlGetHandle(mainFormWindow, "[CLASS:TCMBStyleComboBox; INSTANCE:2]"); EnterComboBoxBox(mainFormWindow, textPostscript, context.BoTransactionId); ClickButton(mainFormWindow, 350, 660); // click 'Next' button Thread.Sleep(TimeSpan.FromSeconds(2)); }
private void FillWithdrawPin(IntPtr mainFormWindow, RobotContext context) { IntPtr textPinBox = AutoItX.ControlGetHandle(mainFormWindow, "[CLASS:TCMBEdit; INSTANCE:1]"); EnterWithdrawPinBox(mainFormWindow, textPinBox, context.TokenWithdrawPin); ClickButton(mainFormWindow, textPinBox, 70, 50); // click 'Next' button Thread.Sleep(GetRandomDelay(1000)); }
protected IntPtr GetHandle(string clazz, int instance) { if (!Running) { return(IntPtr.Zero); } return(AutoItX.ControlGetHandle(process.MainWindowHandle, $"[CLASS:{clazz}; INSTANCE:{instance}]")); }
public static IntPtr GetControlHandle(string title, string control) { IntPtr handle = AutoSpy.GetHandle(title, null); IntPtr result = AutoItX.ControlGetHandle(handle, control); if (result.ToInt32() == 0) { throw new Exception("ControlHandle not found"); } return(result); }
private static void Transfer() { var inputMainPanel = new IntPtr(); FillUpTransferForm(inputMainPanel); if (IsValidTransferForm()) { //SET TRANSFER PASSWORD var txtTransferpass = AutoItX.ControlGetHandle(_mainForm, "[CLASS:TCMBEdit]"); var txtTransferpassPosition = AutoItX.ControlGetPos(_mainForm, txtTransferpass); var elemementPositionX = _windowsPosition.X + txtTransferpassPosition.X; var elemementPositionY = _windowsPosition.Y + txtTransferpassPosition.Y; if (AutoItX.ControlFocus(_mainForm, txtTransferpass) != 1) { return; } Console.WriteLine("Focus on Transfer Password"); AutoItX.WinActivate(_mainForm); SimulateKey.SetForegroundWindow(txtTransferpass); Thread.Sleep(100); SimulateKey.ClearText(txtTransferpass); SimulateKey.SendText(txtTransferpass, Transferpassword); Console.WriteLine($"{Transferpassword}: Transfer Password Set"); Thread.Sleep(1000); Console.WriteLine("Confirm Transfer"); AutoItX.MouseClick("LEFT", elemementPositionX + 80, elemementPositionY + 80); Thread.Sleep(2000); if (ConfirmationMessageFindByClassName("TPbBaseMsgForm", new Tuple <int, int>(200, 180))) { Console.WriteLine("Confirmation Error On Transfer Transaction!"); } if (ConfirmationMessageFindByClassName("TErrorWithHelpForm", new Tuple <int, int>(200, 190))) { Console.WriteLine("Confirmation Error On Transfer Transaction!"); } } }
private static void LogIn() { if (AutoItX.WinActivate("招商银行个人银行专业版_") != 1) { return; } var loginForm = AutoItX.WinGetHandle("招商银行个人银行专业版_"); var txtpass = AutoItX.ControlGetHandle(loginForm, "[CLASS:TCMBStyleEdit72]"); SetPassword(loginForm, txtpass); DoLogIn(loginForm, txtpass); WaitForLogin(loginForm); }
private void FillSameBankTransInfo(IntPtr mainFormWindow, RobotContext context) { IntPtr textToAccountName = AutoItX.ControlGetHandle(mainFormWindow, "[CLASS:TCMBStyleEdit; INSTANCE:2]"); EnterTextBox(mainFormWindow, textToAccountName, context.ToAccountName); IntPtr textToAccountNumber = AutoItX.ControlGetHandle(mainFormWindow, "[CLASS:TCMBStyleEdit; INSTANCE:3]"); Rectangle mainWindowPosition = AutoItX.WinGetPos(mainFormWindow); Rectangle refElementPosition = AutoItX.ControlGetPos(mainFormWindow, textToAccountNumber); int startX = mainWindowPosition.X + refElementPosition.X; int startY = mainWindowPosition.Y + refElementPosition.Y; int elementPossitionX = startX + 20; int elementPossitionY = startY + 20; AutoItX.MouseClick("LEFT", elementPossitionX, elementPossitionY); InputSimulatorUtils.EnterKeysByVirtualKeyboard(context.ToAccountNumber, true); //IntPtr textToAccountNumber = AutoItX.ControlGetHandle(mainFormWindow, "[CLASS:TCMBStyleEdit; INSTANCE:3]"); //EnterTextBox(mainFormWindow, textToAccountNumber, context.ToAccountNumber); IntPtr searchComboBoxToAccountCity = AutoItX.ControlGetHandle(mainFormWindow, "[CLASS:TCMBSearchComboBox; INSTANCE:1]"); SearchAndSelectComboBox(mainFormWindow, searchComboBoxToAccountCity, context.ToAccountCity); IntPtr textTransferAmount = AutoItX.ControlGetHandle(mainFormWindow, "[CLASS:TCMBStyleEdit; INSTANCE:4]"); EnterTextBox(mainFormWindow, textTransferAmount, context.WithdrawAmount); IntPtr textPostscript = AutoItX.ControlGetHandle(mainFormWindow, "[CLASS:TCMBStyleComboBox; INSTANCE:1]"); EnterComboBoxBox(mainFormWindow, textPostscript, context.BoTransactionId); ClickButton(mainFormWindow, 350, 640); // click 'Next' button int warningHappen1 = AutoItX.WinWaitActive("[CLASS:TPbBaseMsgForm]", "选择的收款方地址与收款方账户所属开户地不符", 10); if (warningHappen1 == AutoItXSuccess) { IntPtr warningPopWin1 = AutoItX.WinGetHandle("[CLASS:TPbBaseMsgForm]", "选择的收款方地址与收款方账户所属开户地不符"); ClickButton(warningPopWin1, 300, 150); } }
static void ExportDataAction() { string title = "数据导出"; int handle = AutoItX.WinWait(title, "", 10); if (handle == 0) { throw new InvalidOperationException("failed to find dialog for data exporting"); } IntPtr hwnd = AutoItX.WinGetHandle(title, ""); AutoItX.WinActivate(hwnd); IntPtr buttonAdvancedExport = AutoItX.ControlGetHandle(hwnd, "[CLASSNN:Button6]"); AutoItX.ControlClick(hwnd, buttonAdvancedExport); AdvancedExport(); }
private static void WaitForTransferPage() { var i = 0; while (i < 1000) { AutoItX.MouseClick("LEFT", _windowsPosition.X + 334, _windowsPosition.Y + 470); Console.WriteLine("Click on Transfer Button."); Thread.Sleep(2000); var inputMainPanel = AutoItX.ControlGetHandle(_mainForm, "InputMainPanel"); if (AutoItX.ControlFocus(_mainForm, inputMainPanel) == 1) { Console.WriteLine("Transfer page Found!"); return; } Console.WriteLine("Waiting for Transfer Page"); i++; } throw new Exception("Transfer Page Error!"); }
private static void IsMainFormActivated() { var i = 0; while (i < 1000) { Thread.Sleep(4000); _mainForm = AutoItX.WinGetHandle("招商银行个人银行专业版_"); AutoItX.WinActivate(_mainForm); if (AutoItX.ControlGetText(_mainForm, AutoItX.ControlGetHandle(_mainForm, "[CLASS:TCMBStyleComboBox72; INSTANCE:1]")) == "功能") { Console.WriteLine("Main Page is now Active."); return; } Console.WriteLine("Waiting for Main Page"); i++; } throw new Exception("Cant Find Main Page!"); }
private static void WaitForLogin(IntPtr loginForm) { var i = 0; while (i < 1000) { Thread.Sleep(2000); if (AutoItX.ControlGetText(loginForm, AutoItX.ControlGetHandle(loginForm, "[CLASS:TCMBStyleComboBox72; INSTANCE:1]")) != "功能") { Thread.Sleep(4000); Console.WriteLine("Successfully LogIn.. "); Console.WriteLine("Closing Login Window."); return; } Console.WriteLine("Logging In."); i++; } throw new Exception("Log In Error!"); }
private static bool IsValidTransferForm() { //WAIT FOR TRANSFER PAGE var i = 0; while (i < 1000) { Thread.Sleep(2000); if (ConfirmationMessageFindByClassName("TErrorWithHelpForm", new Tuple <int, int>(200, 200))) { Console.WriteLine("ERROR ON TRANSFER PAGE VALUES"); break; } //正常或校验码确认 //短信校验码确认 var inputMainPanel = AutoItX.ControlGetHandle(_mainForm, "正常或校验码确认"); if (AutoItX.ControlFocus(_mainForm, inputMainPanel) == 1) { Console.WriteLine("Transfer Confirmation page Found!"); return(true); } inputMainPanel = AutoItX.ControlGetHandle(_mainForm, "短信校验码确认"); if (AutoItX.ControlFocus(_mainForm, inputMainPanel) == 1) { Console.WriteLine("Transfer Confirmation page Found!"); return(true); } Console.WriteLine("Waiting for Transfer Confirmation Page"); i++; } Console.WriteLine("Error Transfer Confirmation Not Found"); return(false); }
private void FillBankTransInfo(IntPtr mainFormWindow, RobotContext context) { IntPtr textToAccountName = AutoItX.ControlGetHandle(mainFormWindow, "[CLASS:Edit; INSTANCE:1]"); EnterTextBox(mainFormWindow, textToAccountName, context.ToAccountName); IntPtr textToAccountNumber = AutoItX.ControlGetHandle(mainFormWindow, "[CLASS:TCMBStyleEdit72; INSTANCE:5]"); EnterTextBox(mainFormWindow, textToAccountNumber, context.ToAccountNumber); IntPtr searchComboBoxToAccountBank = AutoItX.ControlGetHandle(mainFormWindow, "[CLASS:TCMBSearchComboBox72; INSTANCE:5]"); AutoItX.ControlClick(mainFormWindow, searchComboBoxToAccountBank); Thread.Sleep(TimeSpan.FromSeconds(1)); IntPtr textTransferAmount = AutoItX.ControlGetHandle(mainFormWindow, "[CLASS:TCMBStyleEdit72; INSTANCE:4]"); EnterTextBox(mainFormWindow, textTransferAmount, context.WithdrawAmount); IntPtr textPostscript = AutoItX.ControlGetHandle(mainFormWindow, "[CLASS:TCMBStyleComboBox72; INSTANCE:2]"); EnterPinBox(mainFormWindow, textPostscript, context.BoTransactionId); }
private bool GetWindow() { if (string.IsNullOrWhiteSpace(WindowNameBox.Text) && string.IsNullOrWhiteSpace(ControlNameBox.Text)) { ErrorLog("Please enter a window- and/or a controlname!"); return(false); } WindowHandle = FindWindow(null, WindowNameBox.Text); if (!string.IsNullOrWhiteSpace(ControlNameBox.Text)) { ControlHandle = AutoItX.ControlGetHandle(WindowHandle, ControlNameBox.Text); if (!IsWindow(WindowHandle) && !IsWindow(ControlHandle)) { BotStarted = false; ErrorLog("Application not found, stopping!"); return(false); } GetWindowRect(ControlHandle, out WindowRect); } else { if (!IsWindow(WindowHandle)) { BotStarted = false; ErrorLog("Application not found, stopping!"); return(false); } GetWindowRect(WindowHandle, out WindowRect); } return(true); }
static void ExportData() { string title = "[TITLE:中信证券金融终端; CLASS:TdxW_MainFrame_Class]"; int handle = AutoItX.WinWait(title, "", 20); if (handle == 0) { throw new InvalidOperationException("failed to find main window"); } IntPtr hwnd = AutoItX.WinGetHandle(title, ""); // close 中信证券消息中心 window AutoItX.WinClose("中信证券消息中心"); // find out main menu entry IntPtr hwndMenu = AutoItX.ControlGetHandle(hwnd, "[CLASSNN:AfxWnd422]"); if (hwndMenu == IntPtr.Zero) { throw new InvalidOperationException("Can't find main menu button"); } // activate the window by click the menu and cancel it. //AutoItX.ControlClick(hwnd, hwndMenu); //AutoItX.Sleep(1000); // wait menu to show. //// goto the download quote menu item //AutoItX.Send("{DOWN}"); //AutoItX.Send("{RIGHT}"); //AutoItX.Send("{DOWN}"); //AutoItX.Send("{DOWN}"); //AutoItX.Send("{DOWN}"); //AutoItX.Send("{DOWN}"); //AutoItX.Send("{DOWN}"); //AutoItX.Send("{DOWN}"); //AutoItX.Send("{DOWN}"); //AutoItX.Send("{DOWN}"); //AutoItX.Send("{DOWN}"); //AutoItX.Send("{DOWN}"); //AutoItX.Send("{ENTER}"); //DownloadQuote(); // export data. // show a stock to enable menu item. if (AutoItX.WinActivate(hwnd) == 0) { throw new InvalidOperationException("failed to activate main window"); } AutoItX.Send("000001"); AutoItX.Send("{ENTER}"); AutoItX.Sleep(2000); AutoItX.Send("34"); // the key shortcut for exporting data AutoItX.Send("{ENTER}"); ExportDataAction(); }
public IntPtr ControlGetHandle(string control = "") { return(AutoItX.ControlGetHandle(thiswindowHandle, control)); }
/// <summary> /// Sends text to file name control of browser open file GUI dialog window and /// presses {Enter} key. Supports single and multiple (from the same folder) /// file(s) upload. Checks whether the dialog was closed afterwards. /// </summary> /// <param name="paths">File(s) with full path</param> public static void Upload(params string[] paths) { if (paths == null || paths.Length == 0 || string.IsNullOrEmpty(paths[0])) { throw new ArgumentException( @"Got null or empty parameter(s). Nothing to upload.", nameof(paths)); } // is it multiple files upload? var isMultipleFilesUpload = paths.Length > 1; // waits for dialog window appearance if (AutoItX.WinWait(WindowTitle, string.Empty, 5) == 0) { throw new AggregateException($@"AutoItX: '{WindowTitle}' dialog window not found"); } // get handles of dialog window, OK button, and File Name input controls _windowHandle = AutoItX.WinGetHandle(WindowTitle); _okControlHandle = AutoItX.ControlGetHandle(_windowHandle, OkControlName); _fileNameControlHandle = AutoItX.ControlGetHandle(_windowHandle, FileNameControlName); if ((int)_windowHandle <= 0 || (int)_okControlHandle <= 0) { throw new AggregateException("AutoItX: Cannot get window or/and control handle(s)"); } // activate dialog window (just in case) AutoItX.WinActivate(_windowHandle); // set uploaded files folder as current folder in case of multiple files selection var dir = Path.GetDirectoryName(paths[0])?.Replace(@"\\", @"\"); if (isMultipleFilesUpload && !string.IsNullOrEmpty(dir)) { // change path // mode: 1 -> no control symbols processing, send text "as is" AutoItX.ControlSend( _windowHandle, AutoItX.ControlGetHandle(_windowHandle, FileNameControlName), dir, mode: 1); // press OK button AutoItX.ControlClick(_windowHandle, _okControlHandle); Thread.Sleep(1000); } // create input string for file name control var path1 = string.Empty; foreach (var path in paths) { path1 += (isMultipleFilesUpload ? "\"" + Path.GetFileName(path) + "\" " : path) .Replace(@"\\", @"\"); // check if dialog is still active and activate it if needed if (AutoItX.WinActive(_windowHandle) != 0) { continue; } if (AutoItX.WinActivate(_windowHandle) == 0) { throw new AggregateException( $@"AutoItX: Cannot activate '{WindowTitle}' dialog window. " + "Is it closed, overlapped or desktop is locked?"); } } // due to upper/lower case AutoIt input typos, following workaround is implemented: // input path to File Name control and verify it afterwards; if wrong, input it // over and over until succeed or timed out var sw = new Stopwatch(); sw.Start(); while (AutoItX.ControlGetText(_windowHandle, _fileNameControlHandle) != path1 && sw.Elapsed < TimeSpan.FromSeconds(60)) { AutoItX.ControlSetText(_windowHandle, _fileNameControlHandle, string.Empty); AutoItX.ControlSend(_windowHandle, _fileNameControlHandle, path1, mode: 1); } sw.Stop(); // if input is timed out, throw exception if (sw.Elapsed >= TimeSpan.FromSeconds(60)) { throw new AggregateException($@"AutoItX: Failed to input path '{path1}'"); } // check if dialog is still active and activate it if not if (AutoItX.WinActive(_windowHandle) == 0) { if (AutoItX.WinActivate(_windowHandle) == 0) { throw new AggregateException( $@"AutoItX: Cannot activate '{WindowTitle}' GUI dialog window. " + "Is it closed, overlapped or desktop is locked?"); } } // press OK button AutoItX.ControlClick(_windowHandle, _okControlHandle); // check if the dialog is closed var success = AutoItX.WinWaitClose(_windowHandle, 1); if (success > 0) { return; } // throw exception if dialog is not closed throw new AggregateException( $@"AutoItX: Failed to close '{WindowTitle}' GUI dialog window. Was this " + "window closed manually, desktop locked, or 'File not found' error " + "displayed?"); }
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"); } }
IntPtr getMenu() { return(AutoItX.ControlGetHandle(_hwnd, "[NAME:menuStrip1]")); }
IntPtr getGrid() { return(AutoItX.ControlGetHandle(_hwnd, "[NAME:gridTesting]")); }
IntPtr getComboBox4() { return(AutoItX.ControlGetHandle(_hwnd, "[REGEXPCLASS:.*COMBOBOX.*; INSTANCE:4]")); }