C# winapi SendMessage 或 PostMessage 怎麽發送一個鍵啊,如F1 setText這個會用了但是發送鍵不會怎麽發送一個鍵啊
[code=C#]
void fun()
{
IntPtr PanentWindow = winapi.FindWindow(null, "计算器");
if (PanentWindow != IntPtr.Zero)
{
IntPtr ChileWindow = winapi.FindWindowEx(PanentWindow,IntPtr.Zero,"Edit",null);
if (ChileWindow != IntPtr.Zero)
{
MessageBox.Show("找到孖窗口");
winapi.SendMessage(ChileWindow, WM_SETTEXT, "Edit", "10005");
}
}code]
------解决方案-------------------- public struct COPYDATASTRUCT
{
public IntPtr dwData;
public int cbData;
[MarshalAs(UnmanagedType.LPStr)]
public string lpData;
}
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(
IntPtr hWnd, // handle to destination window
int Msg, // message
int wParam, // first message parameter
ref COPYDATASTRUCT lParam // second message parameter
);
COPYDATASTRUCT cds;
cds.dwData = (IntPtr)100;
cds.lpData = "Test Message";
cds.cbData = 14;
SendMessage(hwnd_win, WM_SETTEXT, 0, ref cds);
------解决方案--------------------Google
SendInput
------解决方案--------------------PostMessage(WindowHandle, 256, 112, 0);
------解决方案--------------------发送F1按键。