2012-04-19 3 views
0

私はC#でのキー押下をシミュレートしようとしていますし、私はこれらのエラーになっている:私は何かを追加する必要が推測C#PostMessageに必要なライブラリは何ですか?

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 

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 

をして、これはエラーを与えるコードでありますusing System.(something)とは何ですか?手伝ってくれてありがとう。

+1

これらはウィンドウのメッセージ値である必要があります。フレンドリーな列挙が必要な場合は、自分で作成するか、オンラインで見つける必要があります。 – asawyer

答えて

2

これらを自分で定義する必要があります。

[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; 
1

これはUser32.Dllです。自分で指定する必要があります。 Visit this PInvoke.net page on PostMessage for more information

ここでは、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); 
} 
関連する問題