Tried to get chrome to the front again

This commit is contained in:
Ben
2018-09-12 12:59:51 +01:00
parent d67f84dceb
commit c553054e62

View File

@@ -1,33 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;
using System.ComponentModel;
using System.Runtime.InteropServices;
using IronOcr;
using IronOcr.Languages;
namespace TypeRacer_cheat {
class Program {
static void Main(string[] args) {
/* AdvancedOcr ocr = new AdvancedOcr() {
CleanBackgroundNoise = true,
EnhanceContrast = true,
EnhanceResolution = true,
Language = IronOcr.Languages.English.OcrLanguagePack,
Strategy = IronOcr.AdvancedOcr.OcrStrategy.Advanced,
ColorSpace = AdvancedOcr.OcrColorSpace.Color,
DetectWhiteTextOnDarkBackgrounds = true,
InputImageType = AdvancedOcr.InputTypes.AutoDetect,
RotateAndStraighten = true,
ReadBarCodes = true,
ColorDepth = 4
}; */
Run();
AutoOcr ocr = new AutoOcr();
string testImage = @"C:/Users/Ben/Desktop/Programming/Examples/C#/TypeRacer cheat/TypeRacer cheat/bin/Debug/Hey.png";
@@ -37,37 +19,28 @@ namespace TypeRacer_cheat {
Console.WriteLine("Reading image...");
var Results = ocr.Read(image);
Console.WriteLine("OCR OUTPUT: {0}", Results.Text);
Console.ReadKey();
}
static void run() {
Process[] procs = Process.GetProcessesByName("chrome");
static void Run() {
Console.WriteLine("Getting chrome processes");
Process[] ChromeProcs = Process.GetProcessesByName("chrome");
foreach (Process process in procs) {
Console.WriteLine(process);
Console.WriteLine("Testing BringWindowToTop");
foreach (Process ChromeProc in ChromeProcs) {
bool Success = BringWindowToTop(ChromeProc.MainWindowHandle);
if (!Success)
Console.WriteLine($"Method fail: {new Win32Exception(Marshal.GetLastWin32Error()).Message}");
else
Console.WriteLine("Method success");
}
if (procs.Length > 0) {
Console.WriteLine("Bringing chrome forward");
var handle = procs[0].MainWindowHandle;
Console.WriteLine(SetForegroundWindow(handle));
Console.WriteLine(BringWindowToTop(handle));
Console.WriteLine(ShowWindow(handle, 9));
Console.WriteLine("Capturing screen");
Capture.CaptureScreen();
} else {
Console.WriteLine("Could not find chrome...");
}
Console.ReadKey();
Console.WriteLine("Finished");
Console.ReadLine();
}
[DllImport("User32.dll")]
private static extern bool BringWindowToTop(IntPtr hWnd);
[DllImport("User32.dll")]
private static extern bool ShowWindow(IntPtr handle, int nCmdShow);
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
}
class KeyPress {