0
特定のキーが連続して押された場合に送信されるウィンドウに同じメッセージを送信するプログラムを実装しようとしています。 これは、アプリケーションのコード(全体Form1.csのコードがhereである)の一部である:コードプログラムのクラッシュにWM_KEYUPのSendMessageに到達するウィンドウにWM_KEYUPメッセージを送信すると、OverflowExceptionが発生する
[DllImport("User32.dll")]
static extern int SendMessage(IntPtr hWnd, uint wMsg, UIntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, IntPtr windowTitle);
private void button1_Click(object sender, EventArgs e)
{
// find notepad process
System.Diagnostics.Process[] p = System.Diagnostics.Process.GetProcessesByName("notepad");
// find child handle of notepad process
// that is where we can send WM_KEYDOWN, WM_CHAR and WM_KEY up messages to write in the window
IntPtr childHandle = FindWindowEx(p[0].MainWindowHandle, IntPtr.Zero,"Edit", IntPtr.Zero);
// WM_KEYDOWN message with parameters for 1st key
SendMessage(childHandle, (uint)0x0100, (UIntPtr)0x00000041, (IntPtr)(0x001E0001));
// WM_CHAR message with parameters for 1st key
SendMessage(childHandle, (uint)0x0102, (UIntPtr)0x00000061, (IntPtr)(0x001E0001));
// WM_KEYDOWN message with parameters for n-th key
SendMessage(childHandle, (uint)0x0100, (UIntPtr)0x00000041, (IntPtr)(0x401E0001));
// WM_CHAR message with parameters for n-th key
SendMessage(childHandle, (uint)0x0102, (UIntPtr)0x00000061, (IntPtr)(0x401E0001));
// WM_KEYUP message
SendMessage(childHandle, (uint)0x0101, (UIntPtr)0x00000041, (IntPtr)(0xC01E0001));
}
とエラーを与える:
このエラーを修正するにはどうすればよいですか? WM_KEYUPの前に4つのSendMessage呼び出しがうまくいき、2つの文字 'a'をメモ帳に送ります。あなたの返信用
おかげ
私は連続キー入力にできるだけ多くをコピーしたいので、私は(私は次の遅延を行う必要があります)第一選択肢を取ったので、私はUIntPtrたlParamでのIntPtr lParamに置き換えそして予想通り、今、それはなしでメッセージを送信する作品エラー。ありがとうございました! :) –