求助,怎么用c#模拟键盘
展开全部
比较简单的方式
使用system.windows.forms.sendkeys.Send()方春兄法发困哪送键击
参见 http://msdn.microsoft.com/zh-cn/library/system.windows.forms.sendkeys.aspx
比较复杂的方式:
WM_KEYDOWN = 0x0100;// 按下一个 键
WM_KEYUP = 0x0101;
// 释 放一个 键
WM_CHAR = 0x0102;
// 按下某 键 ,并已 扒尺袭发 出 WM_KEYDOWN , WM_KEYUP 消息
using System.Runtime.InteropServices;
[DllImport("user32.dll", EntryPoint="SendMessageA")]
public static extern int SendMessage (IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);
hWnd是窗口的句柄,0就是系统,wParam是键盘码
展开全部
public enum KeyEventType
{
/// <summary>
/// 键盘按下
/// </summary>
KeyDown = 0x0000,
/大困知尺塌// <summary>
/// 扩展
/// </summary>
ExtendedKey = 0x0001,
/// <summary>
/// 键盘释放
/// </summary>
KeyUp = 0x0002
}
[DllImport("user32.dll"滚消)]
private static extern int keybd_event(Keys bVk, byte bScan, KeyEventType dwFlags, int dwExtralnfo);
keybd_event(KeyCode, 0, KeyEventType.KeyDown, 0);//KeyCode是键盘码
{
/// <summary>
/// 键盘按下
/// </summary>
KeyDown = 0x0000,
/大困知尺塌// <summary>
/// 扩展
/// </summary>
ExtendedKey = 0x0001,
/// <summary>
/// 键盘释放
/// </summary>
KeyUp = 0x0002
}
[DllImport("user32.dll"滚消)]
private static extern int keybd_event(Keys bVk, byte bScan, KeyEventType dwFlags, int dwExtralnfo);
keybd_event(KeyCode, 0, KeyEventType.KeyDown, 0);//KeyCode是键盘码
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询