【问题标题】:PostMessage does not work in Windows 7 x64PostMessage 在 Windows 7 x64 中不起作用
【发布时间】:2011-10-02 01:09:24
【问题描述】:

我需要在游戏窗口中模拟按键。我尝试发送密钥“A”,但它不起作用:

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);

[DllImport("user32.dll")]
public static extern IntPtr PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

private void button1_Click(object sender, EventArgs e)
{
    IntPtr hWnd = FindWindow(null, "Game Name");  // it's work!

    if (hWnd == IntPtr.Zero)
    {
        MessageBox.Show("Game is not running");
        return;
    }

    SetForegroundWindow(hWnd);  // it's work too and now I have active window of game
    System.Threading.Thread.Sleep(3000);

    const int WM_KEYDOWN = 0x0100;
    PostMessage(hWnd, WM_KEYDOWN, (IntPtr)Keys.A, IntPtr.Zero);     // don't work ;-(
}

【问题讨论】:

    标签: c# windows-7 64-bit sendmessage postmessage


    【解决方案1】:

    你得到什么错误?游戏是否以管理员身份运行?你可能会被UIPI屏蔽。

    【讨论】:

    • 我没有收到任何错误。在 Spy++ 中,键盘的日志为空。我不认为这是任何障碍,因为其他类似的程序可以毫无问题地使用这个游戏。
    • 对不起伙计,这是我的错误。我忘记以管理员权限运行 Visual Studio
    猜你喜欢
    • 1970-01-01
    • 2012-07-11
    • 2011-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多