public void Click(ICoordinates where) { var MRes = new ManualResetEventSlim(true); MRes.Reset(); Exception exception = null; Task.Run(async() => { try { await mouse.Click(where).ConfigureAwait(false); } catch (Exception ex) { exception = ex; } MRes.Set(); } ); MRes.Wait(); if (exception != null) { throw exception; } }
/// <summary> /// Focuses on the element on which the action is to be performed. /// </summary> protected async Task FocusOnElement(CancellationToken cancellationToken = new CancellationToken()) { if (ActionTarget != null) { await mouse.Click(ActionTarget.Coordinates, cancellationToken); } }
/// <summary> /// Performs a Mouse Click event on the specified element via ILocatable interface. /// </summary> /// <param name="elementName">Element to operate on.</param> public void MouseClick(IWebElement element) { WaitForElementToBePresent(element); ILocatable locatable = (ILocatable)element; mouse.Click(locatable.Coordinates); }
//public override bool ExecuteXpath(string frameId, string xpath) //{ // try // { // driver.SwitchTo().Frame(frameId); // driver.FindElement(By.XPath(xpath)).Click(); // driver.SwitchTo().DefaultContent(); // return true; // return true; // } // catch (Exception ex) // { // Console.WriteLine("ExecuteXpath Error: " + ex.ToString()); // return false; // } //} #endregion public override bool ClickGridItems(string frameId, string xpathExpression, string scenarioName, int stepNumber) { try { if (frameId != null) { driver.SwitchTo().Frame(frameId); driver.FindElement(By.XPath(xpathExpression)).Click(); driver.SwitchTo().DefaultContent(); Direct(scenarioName, stepNumber, 0, null); return(true); } else { ILocatable locatableItem = (ILocatable)this.driver.FindElement(By.XPath(xpathExpression)); IMouse mouse = ((IHasInputDevices)this.driver).Mouse; mouse.Click(locatableItem.Coordinates); Direct(scenarioName, stepNumber, 0, null); return(true); } } catch (Exception ex) { Console.WriteLine("MouseClick Error: " + ex.ToString()); Direct(scenarioName, stepNumber, error, ex.ToString()); return(false); } }
public void SendKeys(int x, int y, string keyString) { if (_mouse != null) { _mouse.Click(x, y); Thread.Sleep(500); } DoKeyboardWork(keyString); }
public void Click(ICoordinates where) { Location location = Location_(where); Logger.Verbose("Click({0})", location); MoveIfNeeded(where); AddMouseTrigger_(MouseAction.Click); Logger.Verbose("Click(): Location is {0}", mouseLocation_); mouse_.Click(where); }
static void Main(string[] args) { IDeviceFactory factory = GetFactoryByCountry("EN"); IMouse mouse = factory.GetMouse(); IKeyboard keyboard = factory.GetKeyboard(); ITouchpad touchpad = factory.GetTouchpad(); mouse.Click(); keyboard.Print(); keyboard.Println(); touchpad.Track(10, 35); }
//private void Refactor() //{ // //Check if WF is running // var wfAlreadyRunning = System.Diagnostics.Process.GetProcessesByName("Warframe.x64").Length > 0; // if (System.Diagnostics.Process.GetProcessesByName("Warframe.x64").Length == 0) // { // Log("Starting warframe"); // StartWarframe(); // } // WaitForLoadingScreen(wfAlreadyRunning); // //Check if on login screen // LogIn(); // //Check if on daily reward screen // ClaimDailyReward(); // //Wait 45 seconds for all of the notifications to clear out. // if (!wfAlreadyRunning) // { // Log("Waiting for talking"); // Thread.Sleep(45 * 1000); // } // //Close any annoying windows it opened // using (var screen = _gameCapture.GetFullImage()) // { // if (_screenStateHandler.IsExitable(screen)) // { // _mouse.Click(3816, 2013); // Thread.Sleep(30); // } // } // //Keep parsing chat as long as we are in a good state. // var lastMessage = DateTime.Now; // var firstParse = true; // while (System.Diagnostics.Process.GetProcessesByName("Warframe.x64").Length > 0 && !cancellationToken.IsCancellationRequested) // { // if (_messageCache.Count > 5000) // { // lock (_messageCache) // { // lock (_messageCacheDetails) // { // while (_messageCache.Count > 5000) // { // string key = null; // //Try to get the earliest key entered in // if (_messageCache.TryDequeue(out key) && key != null) // { // ChatMessageModel empty = null; // //If we fail to remove the detail item add the key back to the cache // if (!_messageCacheDetails.TryRemove(key, out empty)) // _messageCache.Enqueue(key); // } // } // } // } // } // if (!firstParse) // Log("Running loop"); // //Close and try again if no messages in 5 minutes // if (DateTime.Now.Subtract(lastMessage).TotalMinutes > 5) // { // Log("Possible chat connection lost, closing WF"); // CloseWarframe(); // break; // } // //Try doing a parse // SetForegroundWindow(Process.GetProcessesByName("Warframe.x64").First().MainWindowHandle); // using (var screen = _gameCapture.GetFullImage()) // { // _mouse.MoveTo(0, 0); // Thread.Sleep(17); // screen.Save("screen.png"); // var state = _screenStateHandler.GetScreenState(screen); // //Check if we have some weird OK prompt (hotfixes, etc) // if (_screenStateHandler.IsPromptOpen(screen)) // { // Log("Unknown prompt detected. Closing."); // _mouse.Click(screen.Width / 2, (int)(screen.Height * 0.57)); // Thread.Sleep(30); // continue; // } // //If we somehow got off the glyph screen get back on it // if (state != Enums.ScreenState.GlyphWindow) // { // Log("Going to glyph screen."); // GoToGlyphScreenAndSetupFilters(); // Thread.Sleep(30); // //In the event that we did not keep up with chat and ended up in a bad state we need to scroll to the bottom // if (!firstParse) // { // ScrollToBottomAndPause(); // } // continue; // } // else if (state == ScreenState.GlyphWindow && _screenStateHandler.IsChatOpen(screen)) // { // //Wait for the scroll bar before even trying to parse // if (!_chatParser.IsScrollbarPresent(screen)) // { // Thread.Sleep(100); // continue; // } // //On first parse of a new instance scroll to the top // if (firstParse && !wfAlreadyRunning) // { // //Click top of scroll bar to pause chat // if (_chatParser.IsScrollbarPresent(screen)) // { // Log("Scrollbar found. Starting."); // _mouse.MoveTo(3259, 658); // Thread.Sleep(33); // _mouse.Click(3259, 658); // Thread.Sleep(100); // firstParse = false; // continue; // } // } // //On first parse of existing image jump to bottom and pause // else if (firstParse && wfAlreadyRunning) // { // Log("Scrollbar found. Resuming."); // ScrollToBottomAndPause(); // firstParse = false; // continue; // } // var sw = new Stopwatch(); // sw.Start(); // var chatLines = _chatParser.ParseChatImage(screen, true, true, 30); // Log($"Found {chatLines.Length} new messages."); // foreach (var line in chatLines) // { // Log("Processing message: " + line.RawMessage); // lastMessage = DateTime.Now; // if (line is ChatMessageLineResult) // { // var processedCorrectly = ProcessChatMessageLineResult(cropper, line); // if (!processedCorrectly) // { // var path = SaveScreenToDebug(screen); // if (path != null) // _dataSender.AsyncSendDebugMessage("Failed to parse correctly. See: " + path); // _chatParser.InvalidCache(line.GetKey()); // break; // } // } // else // Log("Unknown message: " + line.RawMessage); // } // Thread.Sleep(75); // Log($"Processed (not riven parsed) {chatLines.Length} messages in : {sw.Elapsed.TotalSeconds} seconds"); // sw.Stop(); // } // else // { // Log("Bad state detected! Restarting!!."); // var path = SaveScreenToDebug(screen); // _dataSender.AsyncSendDebugMessage("Bad state detected! Restarting!!. See: " + path); // //We have no idea what state we are in. Kill the game and pray the next iteration has better luck. // CloseWarframe(); // break; // } // } // //Scroll down to get 27 more messages // _mouse.MoveTo(3250, 768); // Thread.Sleep(30); // //Scroll down for new page of messages // for (int i = 0; i < 27; i++) // { // _mouse.ScrollDown(); // Thread.Sleep(17); // } // for (int i = 0; i < 1; i++) // { // _mouse.ScrollUp();//Pause chat // Thread.Sleep(90); // } // _mouse.MoveTo(0, 0); // Thread.Sleep(17); // } //} private async Task StartWarframe() { var existingWarframes = System.Diagnostics.Process.GetProcessesByName("Warframe.x64").ToArray(); ////If not start launcher, click play until WF starts while (true) { var launcher = System.Diagnostics.Process.GetProcessesByName("Launcher").FirstOrDefault(); if (launcher == null) { launcher = new System.Diagnostics.Process() { StartInfo = new System.Diagnostics.ProcessStartInfo() { FileName = _launcherPath } }; launcher.Start(); await Task.Delay(1000); launcher = System.Diagnostics.Process.GetProcessesByName("Launcher").FirstOrDefault(); if (launcher == null) { continue; } } _screenStateHandler.GiveWindowFocus(launcher.MainWindowHandle); var launcherRect = _screenStateHandler.GetWindowRectangle(launcher.MainWindowHandle); _mouse.Click(launcherRect.Left + (int)((launcherRect.Right - launcherRect.Left) * 0.7339181286549708f), launcherRect.Top + (int)((launcherRect.Bottom - launcherRect.Top) * 0.9252336448598131f)); await Task.Delay(17); _keyboard.SendSpace(); await Task.Delay(1000); if (launcher.HasExited) { await Task.Delay(5000); break; } } foreach (var warframe in System.Diagnostics.Process.GetProcessesByName("Warframe.x64").ToArray()) { if (!existingWarframes.Any(eWF => eWF.MainWindowHandle == warframe.MainWindowHandle)) { _warframeProcess = warframe; } } }
/// <summary> /// Clicks at the last coordinates set for the driver. /// </summary> /// <returns>This command always returns <see langword="null"/>.</returns> public override object Execute() { IHasInputDevices hasInputDevicesDriver = this.Session.Driver as IHasInputDevices; IMouse mouse = hasInputDevicesDriver.Mouse; if (this.leftMouseButton) { mouse.Click(null); } else { mouse.ContextClick(null); } return(null); }
public async Task MonitorLive(string debugImageDirectory = null) { _redTextParser.OnRedText += async redtext => await _dataSender.AsyncSendRedtext(redtext); if (debugImageDirectory != null && !Directory.Exists(debugImageDirectory)) { Directory.CreateDirectory(debugImageDirectory); } if (!Directory.Exists(Path.Combine(Path.GetTempPath(), "wfchat"))) { Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "wfchat")); } if (!Directory.Exists(Path.Combine(Path.GetTempPath(), "wfchat", "rivens"))) { Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "wfchat", "rivens")); } foreach (var oldRiven in Directory.GetFiles(Path.Combine(Path.GetTempPath(), "wfchat", "rivens"))) { File.Delete(oldRiven); } var newSW = new Stopwatch(); var sw = new Stopwatch(); var scrollbarFound = false; Bitmap b = null; var scrollDots = 0; var cachedRivens = new Queue <string>(); var cachedRivenValues = new Dictionary <string, Riven>(); while (true) { UpdateUISeperators(); _UISecondLine = null; UpdateUISecondLine(); _UIThirdLine = null; UpdateUIThirdLine(); if (!scrollbarFound) { _UIFirstLine = "Finding scrollbar"; } else { _UIFirstLine = "Getting image"; } UpdateUIFirstLine(); newSW.Restart(); sw.Restart(); //var image = string.Empty; //try //{ // newSW.Restart(); // b = _gameCapture.GetFullImage(); // b.Save(Path.Combine(Path.GetTempPath(), "wfchat", "capture_0.png")); // b.Dispose(); // image = Path.Combine(Path.GetTempPath(), "wfchat", "capture_0.png"); // if (debugImageDectory != null) // { // File.Copy(image, Path.Combine(debugImageDectory, "capture_0.png"), true); // } //} //catch { continue; } var imageTime = sw.Elapsed.TotalSeconds; sw.Restart(); var image = _gameCapture.GetFullImage(); image.Save("image.png"); if (image == null) { _UIFirstLine = "Failed to get image"; UpdateUIFirstLine(); continue; } if (!_screenStateHandler.IsChatOpen(image)) { if (_screenStateHandler.IsExitable(image)) { _UIFirstLine = "RECOVERING: clickign exit"; UpdateUIFirstLine(); //Click exit _mouseMover.Click(3814, 2014); await Task.Delay(30); continue; } await _dataSender.AsyncSendDebugMessage("Help I'm stuck!"); await Task.Delay(5000); image.Dispose(); continue; } //Wait for scrollbar to be ready if (!scrollbarFound) { if (_chatParser.IsScrollbarPresent(image)) { scrollbarFound = true; _mouseMover.MoveTo(3259, 658); await Task.Delay(33); _mouseMover.Click(3259, 658); await Task.Delay(100); continue; } else { scrollDots++; if (scrollDots > 4) { scrollDots = 0; } await Task.Delay(100); continue; } } sw.Restart(); newSW.Restart(); _UIFirstLine = "Parsing chat"; UpdateUIFirstLine(); newSW.Restart(); var lines = _chatParser.ParseChatImage(image, true, true, 27); _UIMessages.AddRange(lines.Select(l => l.RawMessage)); _UIFirstLine = "Parsing chat: " + lines.Length + " new messages. Riven cache count: " + cachedRivens.Count; UpdateUIFirstLine(); UpdateUIMessages(); var parseTime = sw.Elapsed.TotalSeconds; sw.Restart(); string debugImageName = null; if (debugImageDirectory != null) { debugImageName = Path.Combine(debugImageDirectory, "debug_image_" + DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss-fff") + ".png"); } var newMessags = 0; var shouldCopyImage = false; var badNameRegex = new Regex("[^-A-Za-z0-9._]"); //[00:00] f: . ChatMessageModel lastMessage = null; var hasher = MD5.Create(); sw.Restart(); var linesBad = false; var rivenParseTime = 0.0; var sendingTime = 0.0; var rivenSW = new Stopwatch(); var sendingSW = new Stopwatch(); foreach (var line in lines) { _UISecondLine = "Handling generic: " + line.RawMessage; UpdateUISecondLine(); var lineSw = new Stopwatch(); lineSw.Start(); if (linesBad) { lines.ToList().ForEach(l => _chatParser.InvalidCache(l.GetKey())); break; } //if (line.LineType == LineParseResult.LineType.RedText) //{ // _UISecondLine = "Handing redtext: " + line.RawMessage; // UpdateUISecondLine(); // //await _dataSender.AsyncSendRedtext(line.RawMessage); //} if (line.LineType == LineParseResult.LineType.NewMessage && line is ChatMessageLineResult) { _UISecondLine = "Current msg: " + line.RawMessage; UpdateUISecondLine(); var chatMessageSw = new Stopwatch(); chatMessageSw.Start(); newSW.Restart(); var clr = line as ChatMessageLineResult; var message = MakeChatModel(line as LineParseResult.ChatMessageLineResult, badNameRegex); if (!Regex.Match(message.Raw, @"^(\[\d\d:\d\d\]) ([-A-Za-z0-9._]+):?\s+(.+)").Success) { message.DEBUGREASON = "Invalid username or timestamp!"; } newMessags++; for (int i = 0; i < clr.ClickPoints.Count; i++) { var clickPointSw = new Stopwatch(); clickPointSw.Start(); rivenSW.Restart(); var clickpoint = clr.ClickPoints[i]; _UIThirdLine = "Parsing riven: " + clickpoint.RivenName + " " + clickpoint.X + "," + clickpoint.Y; UpdateUIThirdLine(); if (cachedRivenValues.ContainsKey(clr.Username + clickpoint.RivenName)) { var cachedRiven = cachedRivenValues[clr.Username + clickpoint.RivenName]; var copiedRiven = new Riven(); copiedRiven.Drain = cachedRiven.Drain; copiedRiven.ImageId = cachedRiven.ImageId; copiedRiven.MasteryRank = cachedRiven.MasteryRank; copiedRiven.MessagePlacementId = clickpoint.Index; copiedRiven.Modifiers = cachedRiven.Modifiers; copiedRiven.Name = cachedRiven.Name; copiedRiven.Polarity = cachedRiven.Polarity; copiedRiven.Rank = cachedRiven.Rank; copiedRiven.Rolls = cachedRiven.Rolls; message.Rivens.Add(copiedRiven); rivenParseTime += rivenSW.Elapsed.TotalSeconds; await _dataSender.AsyncSendDebugMessage("Found a riven from cache: " + clr.Username + " " + clickpoint.RivenName); _UISecondLine = "Riven: " + clickpoint.RivenName + " found in cache"; _UILastRiven = cachedRiven; UpdateUISecondLine(); //UpdateUIRiven(cachedRiven); continue; } var rivenImage = string.Empty; var originalBytes = Encoding.UTF8.GetBytes(clr.Username); var hashedBytes = hasher.ComputeHash(originalBytes); var usernameHash = new StringBuilder(); foreach (Byte hashed in hashedBytes) { usernameHash.AppendFormat("{0:x2}", hashed); } rivenImage = Path.Combine(Path.GetTempPath(), "wfchat", "rivens", usernameHash.ToString() + "_" + i + ".png"); b = _gameCapture.GetChatIcon(); if (_chatParser.IsChatFocused(b)) { _mouseMover.MoveTo(clickpoint.X, clickpoint.Y); await Task.Delay(30); _mouseMover.Click(clickpoint.X, clickpoint.Y); await Task.Delay(80); } else { _chatParser.InvalidCache(line.GetKey()); linesBad = true; rivenParseTime += rivenSW.Elapsed.TotalSeconds; break; } b.Dispose(); _mouseMover.MoveTo(0, 0); Bitmap crop = null; var foundRiven = false; for (int tries = 0; tries < 15; tries++) { b = _gameCapture.GetFullImage(); if (_screenStateHandler.GetScreenState(b) == ScreenState.RivenWindow) { foundRiven = true; crop = _rivenParser.CropToRiven(b); b.Dispose(); _mouseMover.Click(3816, 2013); await Task.Delay(160); _mouseMover.MoveTo(0, 0); await Task.Delay(17); break; } b.Dispose(); } if (!foundRiven || crop == null) { linesBad = true; _chatParser.InvalidCache(line.GetKey()); if (crop != null) { crop.Dispose(); } rivenParseTime += rivenSW.Elapsed.TotalSeconds; break; } var newC = _rivenCleaner.CleanRiven(crop); var riven = _rivenParser.ParseRivenTextFromImage(newC, clickpoint.RivenName); riven.Name = clickpoint.RivenName; riven.Polarity = _rivenParser.ParseRivenPolarityFromColorImage(crop); riven.Rank = _rivenParser.ParseRivenRankFromColorImage(crop); newC.Dispose(); //crop.Dispose(); if (riven == null) { //crop.Dispose(); _chatParser.InvalidCache(line.GetKey()); linesBad = true; rivenParseTime += rivenSW.Elapsed.TotalSeconds; break; } riven.MessagePlacementId = clickpoint.Index; if (riven.Drain > 0 && riven.MasteryRank > 0) { cachedRivens.Enqueue(clr.Username + clickpoint.RivenName); cachedRivenValues[clr.Username + clickpoint.RivenName] = riven; while (cachedRivens.Count > 5000) { var removed = cachedRivens.Dequeue(); cachedRivenValues.Remove(removed); } _UIFirstLine = "Parsing chat: " + lines.Length + " new messages. Riven cache count: " + cachedRivens.Count; UpdateUIFirstLine(); } message.Rivens.Add(riven); _UILastRiven = riven; crop.Save(riven.ImageId + ".png"); UpdateUIRiven(riven); File.Delete(rivenImage); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed _dataSender.AsyncSendRivenImage(riven.ImageId, crop); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed //await _dataSender.AsyncSendRivenImage(riven.ImageID, rivenBase64); for (int tries = 0; tries < 15; tries++) { b = _gameCapture.GetFullImage(); var state = _screenStateHandler.GetScreenState(b); if (_screenStateHandler.IsChatOpen(b)) { b.Dispose(); break; } else if (tries > 10 && state == ScreenState.RivenWindow) { _mouseMover.Click(3816, 2013); await Task.Delay(250); _mouseMover.MoveTo(0, 0); await Task.Delay(17); } else { await Task.Delay(80); } b.Dispose(); } } if (linesBad) { lines.ToList().ForEach(l => _chatParser.InvalidCache(l.GetKey())); break; } if (message.DEBUGREASON != null) { message.DEBUGIMAGE = debugImageName; shouldCopyImage = true; } rivenParseTime += rivenSW.Elapsed.TotalSeconds; sendingSW.Restart(); await _dataSender.AsyncSendChatMessage(message); sendingTime += sendingSW.Elapsed.TotalSeconds; } } if (shouldCopyImage && debugImageName != null && debugImageName.Length > 0) { try { File.Copy("image.png", debugImageName); image.Save(debugImageName); } catch { } } image.Dispose(); var transmitTime = sw.Elapsed.TotalSeconds; sw.Stop(); var debugMessage = $"Image capture: {imageTime:00.00} Parse time: {parseTime:00.00} TransmitTime: {transmitTime:0.000} New messages {newMessags} {newMessags / parseTime}/s"; await _dataSender.AsyncSendDebugMessage(debugMessage); _UIFirstLine = "Scrolling"; _UISecondLine = null; _UIThirdLine = null; UpdateUIFirstLine(); UpdateUISecondLine(); UpdateUIThirdLine(); //Scroll down to get 27 more messages _mouseMover.MoveTo(3250, 768); //Scroll down for new page of messages for (int i = 0; i < 27; i++) { _mouseMover.ScrollDown(); await Task.Delay(17); } for (int i = 0; i < 1; i++) { _mouseMover.ScrollUp();//Pause chat await Task.Delay(17); } _mouseMover.MoveTo(0, 0); await Task.Delay(100); } }
/// <summary> /// Performs a Mouse Click event on the specified element via ILocatable interface. /// </summary> /// <param name="elementName">Element to operate on.</param> public void MouseClick(IWebElement element) { ILocatable locatable = (ILocatable)element; mouse.Click(locatable.Coordinates); }