using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;
using System.Drawing;
namespace TextSendKeys
{
class Program
{
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
static void Main(string[] args)
{
Process[] processes = Process.GetProcessesByName("game");
Process game1 = processes[0];
IntPtr p = game1.MainWindowHandle;
ShowWindow(p,1);
SendKeys.SendWait("{DOWN}");
Thread.Sleep(1000);
SendKeys.SendWait("{DOWN}");
}
}
}
该程序应该在游戏窗口中发送两次DOWN按钮。它仅在最小化我的窗口时才起作用(它正在激活窗口并完成工作)。如果我的窗口被激活(未最小化),则什么都不会发生。怎么解决呢?
谢谢! :)
尝试使用SetForegroundWindow
Win32 API而不是SetForegroundWindow
来激活游戏窗口。 (来自ShowWindow
的签名。)
pinvoke.net
非常感谢道格拉斯。您对此非常有技巧...