[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
const int KEYEVENTF_EXTENDEDKEY = 0x1;
const int KEYEVENTF_KEYUP = 0x2;
public Form2()
{
keybd_event((byte)Keys.NumLock, 0, KEYEVENTF_EXTENDEDKEY, 0);//鎖上小鍵盤
// keybd_event((byte)Keys.NumLock, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);//2條語句都可以實現,這2條語句都執行則解鎖
InitializeComponent();
}
摘自 Bychentufeiyang的專欄