【发布时间】:2026-02-15 08:35:01
【问题描述】:
我正在尝试运行一个有时会在 GTA:SA 中模拟点击的程序。问题是它在运行时什么都不做。到目前为止,我已经尝试过这段代码:
IntPtr calculatorHandle = FindWindow(null, "GTA:SA:MP");
if (calculatorHandle == IntPtr.Zero)
{
MessageBox.Show("GTA:SA:MP isn't running");
return;
}
SetForegroundWindow(calculatorHandle);
SendKeys.SendWait("T123");
如果你能告诉我我的代码是否有问题,我会很高兴。谢谢!
编辑
这是我添加尼尔的代码后的代码:
IntPtr calculatorHandle = FindWindow(null, "GTA:SA:MP");
if (calculatorHandle == IntPtr.Zero)
{
MessageBox.Show("GTA:SA:MP isn't running");
return;
}
SetForegroundWindow(calculatorHandle);
short key = 0x14;
WindowsMessageService.SendKey(key, KeyFlag.KeyDown);
Thread.Sleep(10);
WindowsMessageService.SendKey(key, KeyFlag.KeyUp);
【问题讨论】:
标签: c# winforms sendkeys intptr