C#后台模拟按键
已知窗口句柄MyPtr有什么方法后台模拟MyPtr这个窗口按下A键呢??SendKeys.Send("A");只能前台操作,求后台!!!!!!...
已知窗口句柄 MyPtr 有什么方法后台模拟MyPtr这个窗口按下 A 键呢??SendKeys.Send("A");只能前台操作,求后台!!!!!!
展开
1个回答
展开全部
可以尝试使用api:SendMessage
参数分别是SendMessage(句柄,命令,键码,0)
命令:
WM_KEYDOWN 键盘按下
WM_KEYUP 按键弹起
例子:
SendMessage(MyPtr, WM_KEYDOWN, VK_SPACE, 0);
SendMessage(MyPtr, WM_KEYUP, VK_SPACE, 0);
参考声明:
const int WM_KEYDOWN = 0x0100;
const int WM_KEYUP = 0x0101;
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
参数分别是SendMessage(句柄,命令,键码,0)
命令:
WM_KEYDOWN 键盘按下
WM_KEYUP 按键弹起
例子:
SendMessage(MyPtr, WM_KEYDOWN, VK_SPACE, 0);
SendMessage(MyPtr, WM_KEYUP, VK_SPACE, 0);
参考声明:
const int WM_KEYDOWN = 0x0100;
const int WM_KEYUP = 0x0101;
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询