Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 什么是PostMessage所必需的库?_C#_Keydown_Postmessage - Fatal编程技术网

C# 什么是PostMessage所必需的库?

C# 什么是PostMessage所必需的库?,c#,keydown,postmessage,C#,Keydown,Postmessage,我试图在C#中模拟按键,我得到了以下错误: Error 2 The name 'WM_KEYDOWN' does not exist in the current context c:\users\frk\documents\visual studio 2010\Projects\HaxBot3\HaxBot3\Form1.cs 28 52 HaxBot3 Error 5 The name 'WM_KEYDOWN' does not exist in the current

我试图在C#中模拟按键,我得到了以下错误:

Error   2   The name 'WM_KEYDOWN' does not exist in the current context c:\users\frk\documents\visual studio 2010\Projects\HaxBot3\HaxBot3\Form1.cs 28  52  HaxBot3
Error   5   The name 'WM_KEYDOWN' does not exist in the current context c:\users\frk\documents\visual studio 2010\Projects\HaxBot3\HaxBot3\Form1.cs 29  52  HaxBot3
Error   8   The name 'WM_KEYDOWN' does not exist in the current context c:\users\frk\documents\visual studio 2010\Projects\HaxBot3\HaxBot3\Form1.cs 30  52  HaxBot3
Error   9   The name 'VK_RIGHT' does not exist in the current context   c:\users\frk\documents\visual studio 2010\Projects\HaxBot3\HaxBot3\Form1.cs 30  64  HaxBot3
Error   3   The name 'VK_CONTROL' does not exist in the current context c:\users\frk\documents\visual studio 2010\Projects\HaxBot3\HaxBot3\Form1.cs 28  64  HaxBot3
Error   6   The name 'VK_ALT' does not exist in the current context c:\users\frk\documents\visual studio 2010\Projects\HaxBot3\HaxBot3\Form1.cs 29  64  HaxBot3
Error   1   The name 'PostMessage' does not exist in the current context    c:\users\frk\documents\visual studio 2010\Projects\HaxBot3\HaxBot3\Form1.cs 28  17  HaxBot3
Error   4   The name 'PostMessage' does not exist in the current context    c:\users\frk\documents\visual studio 2010\Projects\HaxBot3\HaxBot3\Form1.cs 29  17  HaxBot3
Error   7   The name 'PostMessage' does not exist in the current context    c:\users\frk\documents\visual studio 2010\Projects\HaxBot3\HaxBot3\Form1.cs 30  17  HaxBot3
这是给出错误的代码:

public static void Forward()
        {
            Process[] processes = Process.GetProcessesByName("test");

            foreach (Process proc in processes)
            {
                PostMessage(proc.MainWindowHandle, WM_KEYDOWN, VK_CONTROL, 0);
                PostMessage(proc.MainWindowHandle, WM_KEYDOWN, VK_ALT, 0);
                PostMessage(proc.MainWindowHandle, WM_KEYDOWN, VK_RIGHT, 0);
            }
        }//Fprward

我想我必须添加一些使用系统的
。(一些东西)
但是什么呢?谢谢您的帮助。

它位于User32.Dll中。您需要自己指定

下面是一个示例类,假设
Forward()
在类
MyClass

public static class MyClass
{
  public static void Forward()
  {
     /* snip */
  }

  [return: MarshalAs(UnmanagedType.Bool)]
  [DllImport("user32.dll", SetLastError = true)]
  static extern bool PostMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
}

它在User32.Dll中。您需要自己指定

下面是一个示例类,假设
Forward()
在类
MyClass

public static class MyClass
{
  public static void Forward()
  {
     /* snip */
  }

  [return: MarshalAs(UnmanagedType.Bool)]
  [DllImport("user32.dll", SetLastError = true)]
  static extern bool PostMessage(HandleRef hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
}

你需要自己定义这些

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

public const uint WM_KEYDOWN = 0x0100;
public const uint VK_RIGHT = 27;
public const uint VK_CONTROL = 11;
public const uint VK_ALT = 12;

你需要自己定义这些

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

public const uint WM_KEYDOWN = 0x0100;
public const uint VK_RIGHT = 27;
public const uint VK_CONTROL = 11;
public const uint VK_ALT = 12;

它们应该是windows消息值。如果您想要一个友好的枚举,您必须编写自己的枚举,或者在线查找。它们应该是windows消息值。如果你想要一个友好的枚举,你必须自己写,或者在网上找到一个。