Untitled
using System; using System.Threading; using System.Threading.Tasks; using System.Runtime.InteropServices; using Tenjoyer; public class KeyControlSystem { [DllImport("user32.dll")] private static extern short GetAsyncKeyState(int vKey); private const int VK_LBUTTON = 0x1; // Sol mouse tuşu private const int VK_TAB = 0x09; // Tab tuşu private volatile bool isRunning = false; private CancellationTokenSource cancellationTokenSource; private readonly ContinuousRegionMatcher regionMatcher; private bool isTabPressed = false; public KeyControlSystem(ContinuousRegionMatcher matcher) { this.regionMatcher = matcher; this.cancellationTokenSource = new CancellationTokenSource(); } public void StartControl() { if (isRunning) return; isRunning = true; cancellationTokenSource = new CancellationTokenSource(); Task.Run(async () => await ControlLoop(cancellationTokenSource.Token), cancellationTokenSource.Token); } public void StopControl() { isRunning = false; cancellationTokenSource.Cancel(); } private async Task ControlLoop(CancellationToken token) { bool wasRegion4Active = false; bool isProcessing = false; while (!token.IsCancellationRequested && isRunning) { try { // Sağ tuş kontrolü bool isRightMousePressed = (GetAsyncKeyState(VK_LBUTTON) & 0x8000) != 0; // Tab tuşu kontrolü bool currentTabState = (GetAsyncKeyState(VK_TAB) & 0x8000) != 0; if (currentTabState && !isTabPressed) { isTabPressed = true; isProcessing = true; } else if (!currentTabState && isTabPressed) { isTabPressed = false; } if (!isProcessing) { await Task.Delay(10, token); continue; } if (isRightMousePressed) //sağ tık basılıysa döngüyü iptal et tab yapma { isProcessing = false; await Task.Delay(10, token); continue; } bool region2Active = ContinuousRegionMatcher.Region2Result; // hata mesajlarını okuma bool region3Active = ContinuousRegionMatcher.Region3Result; //korumada'mı smoke screen varmı ? bool region4Active = ContinuousRegionMatcher.Region4Result; //dps kontrolü simge arama if (region4Active && !region2Active && !region3Active) //dps resmi bulunduysa hata mesajı yoksa ve protection smoke screen yoksa tabı durdur { wasRegion4Active = true; Console.Beep(100, 100); await Task.Delay(50, token); continue; } if (wasRegion4Active && (region2Active || region3Active)) //dps bulundu ama hata aldıysa veya sonradan smokescreen bastıysa veya protection moda geçtiyse { mouse.SendTimeout(88); // X tuşu await Task.Delay(50, token); wasRegion4Active = false; } if (!region4Active || (region2Active || region3Active)) // hiç bir koşul sağlanmıyorsa tab basmaya devam et { mouse.SendTimeout(9); // TAB tuşu wasRegion4Active = false; await Task.Delay(100, token); } } catch (OperationCanceledException) { break; } catch (Exception ex) { Console.WriteLine($"Kontrol döngüsünde hata: {ex.Message}"); await Task.Delay(1000, token); } } } }
Leave a Comment