Her King™
Explore posts from servers"Bot" for Last Chaos Game
$code
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
namespace Karho
{
public partial class Form1 : Form
{
[DllImport("user32.dll")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
private Thread sendKeysThread;
private bool isSendingKeys = false;
public Form1()
{
InitializeComponent();
LoadRunningApplications(); // Lade die laufenden Anwendungen beim Starten der Form
}
private void LoadRunningApplications()
{
if (InvokeRequired)
{
Invoke(new Action(LoadRunningApplications));
return;
}
comboBoxApplications.Items.Clear();
Process[] processes = Process.GetProcesses();
foreach (var process in processes)
{
if (!string.IsNullOrEmpty(process.MainWindowTitle))
{
// Überprüfen, ob der Prozess den gewünschten Namen oder Fenstertitel hat
if (process.ProcessName.Equals("Nksp", StringComparison.OrdinalIgnoreCase)
process.ProcessName.Equals("Nksp.exe", StringComparison.OrdinalIgnoreCase)
process.MainWindowTitle.IndexOf("Last Chaos", StringComparison.OrdinalIgnoreCase) >= 0)
{
comboBoxApplications.Items.Add(process.MainWindowTitle);
}
}
}
}
private void buttonStart_Click(object sender, EventArgs e)
{
if (comboBoxApplications.SelectedItem == null)
{
MessageBox.Show("Bitte wähle eine Anwendung aus der Liste aus.");
return;
}
isSendingKeys = true;
sendKeysThread = new Thread(SendKeysLoop);
sendKeysThread.Start();
}
private void buttonStop_Click(object sender, EventArgs e)
{
isSendingKeys = false;
if (sendKeysThread != null && sendKeysThread.IsAlive)
{
sendKeysThread.Join();
}
}
private void buttonRefresh_Click(object sender, EventArgs e)
{
LoadRunningApplications();
}
private void SendKeysLoop()
{
IntPtr hWnd = IntPtr.Zero;
// Zugriff auf die ausgewählte Anwendung soll im UI-Thread erfolgen
if (InvokeRequired)
{
Invoke(new Action(() => hWnd = FindWindow(null, comboBoxApplications.SelectedItem.ToString())));
}
else
{
hWnd = FindWindow(null, comboBoxApplications.SelectedItem.ToString());
}
if (hWnd == IntPtr.Zero)
{
MessageBox.Show("Fenster konnte nicht gefunden werden.");
return;
}
while (isSendingKeys)
{
// Setze das Fenster in den Vordergrund im UI-Thread
if (InvokeRequired)
{
Invoke(new Action(() => SetForegroundWindow(hWnd)));
}
else
{
SetForegroundWindow(hWnd);
}
SendKeys.SendWait("1");
Thread.Sleep(1000);
SendKeys.SendWait("2");
Thread.Sleep(1000);
SendKeys.SendWait("{TAB}");
Thread.Sleep(1000);
}
}
}
}
So this is my code and when I chose the right program (NKSP/LastChaos) It wont send the theys which I want to send ?
Maybe anyone know this issues?
10 replies