最近做一个项目用到键盘输入,试了很多种普通的模拟键盘输入,都是实现不了,特别是到输入密码这块,根本输入不了,最后用到了这个WinIo驱动级的输入才搞定的,以下是具体代码:
#region 驱动级键盘输入定义
//键盘输入
// public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
//[DllImport("User32.dll")]
//public static extern void keybd_event(Byte bVk, Byte bScan, Int32 dwFlags, Int32 dwExtraInfo);
//private const int KEYEVENTF_KEYUP = 2;
//winio开始
public const int KBC_KEY_CMD = 0x64;
public const int KBC_KEY_DATA = 0x60;
[DllImport("WinIo32.dll")]
public static extern bool InitializeWinIo();
[DllImport("WinIo32.dll")]
public static extern bool GetPortVal(IntPtr wPortAddr, out int pdwPortVal,
byte bSize);
[DllImport("WinIo32.dll")]
public static extern bool SetPortVal(uint wPortAddr, IntPtr dwPortVal,
byte bSize);
[DllImport("WinIo32.dll")]
public static extern byte MapPhysToLin(byte pbPhysAddr, uint dwPhysSize,
IntPtr PhysicalMemoryHandle);
[DllImport("WinIo32.dll")]
public static extern bool UnmapPhysicalMemory(IntPtr PhysicalMemoryHandle,
&