C#中调用user32.dll库的keybd_Event函数,操作键盘

keybd_event()的函数原型是:

    void keybd_event(

         byte bVk,          //虚拟键码

         byte bScan,       //该键的硬件扫描码

         dword dwFlags   //函数操作的各个方面的一个标志位集

         dword dwExtraInfo  //与击键相关的附加的32位值

    );

其中第三个参数有三种取值:

  · 0:按下

  · 1:扩展键

  · 2:弹起

keybd_event(0x41, 0x1e, 0x0000, 0);   // 按下 a
keybd_event(0x41, 0x1e, 0x0002, 0);   // 弹起 a
keybd_event(0x42, 0x30, 0x0000, 0);   // 按下 b
keybd_event(0x42, 0x30, 0x0002, 0);   // 弹起 b
keybd_event(0x43, 0x2e, 0x0000, 0);   // 按下 c
keybd_event(0x43, 0x2e, 0x0002, 0);   // 弹起 c
keybd_event(0x43, 0x2e, 0x0000, 0);   // 按下 c
keybd_event(0x43, 0x2e, 0x0002, 0);   // 弹起 c

  

原文地址:https://www.cnblogs.com/pocn/p/5644707.html