c# 中如何通过sendMessage或postMessage给桌面最顶层的窗体发送一个回车?
1个回答
展开全部
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll ")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
private void button1_Click(object sender, EventArgs e)
{
IntPtr hwnd = GetForegroundWindow();//取前台窗体句柄
SendMessage(hwnd, 256, 0xD, 0);//按下回车键
//SendMessage(hwnd, 257, 0xD, 0);//弹起回车键
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询