keybd_event使用方法 - 小众知识

keybd_event使用方法

2013年01月27日 14:18:05 苏内容
  标签:
阅读:7328

Windows提供了一个模拟键盘API函数Keybd_event(),使用该函数可以相应的屏蔽键盘的动作。Keybd_event()函数能触发一个按键事件,也就是说会产生一个WM_KEYDOWN或WM_KEYUP消息。

 

该函数原型如下:

  VOID keybd_event(

  BYTE bVk, // virtual-key code

  BYTE bScan, // hardware scan code

  DWORD dwFlags, // flags specifying various function options

  DWORD dwExtraInfo // additional data associated with keystroke

  );

  从原型可以看出,Keybd_event()共有四个参数:

      第一个为按键的虚拟键值,如回车键为vk_return, tab键为vk_tab(其他具体的参见附录:常用模拟键的键值对照表);

      第二个参数为扫描码,一般不用设置,用0代替就行;

      第三个参数为选项标志,如果为keydown则置0即可,如果为keyup则设成"KEYEVENTF_KEYUP";

      第四个参数一般也是置0即可。

 

例子1:模拟按下'A'键
   keybd_event(65,0,0,0);
   keybd_event(65,0,KEYEVENTF_KEYUP,0);

 

例子2:模拟按下'ALT+F4'键
   keybd_event(18,0,0,0);
   keybd_event(115,0,0,0);
   keybd_event(115,0,KEYEVENTF_KEYUP,0);
   keybd_event(18,0,KEYEVENTF_KEYUP,0);

 

附:常用模拟键的键值对照表(也可参考http://msdn.microsoft.com/en-us/library/dd375731(v=vs.85).aspx

 

 

                                                         键盘键与虚拟键码对照表

 

      字母和数字键 数字小键盘的键 功能键 其它键 
      键   键码    键   键码    键   键码     键    键码 
      A   65     0   96     F1   112   Backspace    8 
      B   66     1   97     F2   113   Tab       9 
      C   67     2   98      F3   114    Clear      12 
      D   68   3   99     F4   115  Enter      13 
      E   69     4   100    F5   116  Shift      16 
      F   70     5   101    F6   117  Control     17 
      G   71     6   102    F7   118   Alt       18 
      H   72    7   103    F8   119  Caps Lock    20 
      I   73    8   104    F9   120  Esc       27 
      J   74    9   105    F10  121  Spacebar    32 
      K   75    *   106     F11  122  Page Up     33 
      L   76    +   107     F12  123  Page Down    34 
      M   77    Enter 108    --   --   End       35 
      N   78    -   109    --   --    Home      36 
      O   79    .   110    --   --     Left Arrow   37 
      P   80    /   111    --   --     Up Arrow    38 
      Q   81    --   --     --   --     Right Arrow   39 
      R   82    --   --    --   --      Down Arrow    40 
      S   83    --   --     --   --     Insert      45 
      T   84    --   --     --   --     Delete      46 
      U   85    --   --     --   --     Help       47 
      V   86    --   --    --   --     Num Lock     144 
      W   87          
      X   88      
      Y   89      
      Z   90      
      0   48      
      1   49      
      2   50       
      3   51       
      4   52       
      5   53       
      6   54       
      7   55       
      8   56       
      9   57  

扩展阅读

Suese

2018-02-03 09:11:13

Who Makes Amoxicillin <a href=http://cial20mg.com>cialis</a> Propecia Valoracion

Suese

2018-03-29 14:51:57

kamagra 100mg tablets usage <a href="http://kamagradxt.com/">buy kamagra 100mg</a> ajanta kamagra 100 chewable <a href="http://kamagradxt.com/">buy kamagra 100 mg oral jelly</a> kamagra kopen rotterdam winkel http://kamagradxt.com/ kamagra bestellen

Suese

2018-04-15 19:39:54

Online Propecia Without Prescription Misoprostol Grossesse Evolutive <a href=http://cheapciali.com>cialis vs viagra</a> Effets Cialis Levitra Rayh Healthcare Durata Effetto Levitra

Suese

2018-05-06 06:13:43

Thats the problem. Angelicas husband is a morose brute who, according to rumour, bashes her on a regular basis. She often wears scarves and long sleeves and trousers, which I assume are to conceal bruises. Both women are childless. Before Mort arrived they were like everyones mother, maiden aunt and fairy godmother combined. The kids hung on their every word and made them feel loved and important. But over the last year the affections of most of the kids have been transferred to Mort. Youve no idea what an angel of mercy he is. Always ready to listen, to enter into their fantasy games, praise and encourage. He seems to be a bottomless pit of good sense, good humour and exactly the sort of relationship these kids need—friendship that comes with absolutely no strings attached, unlike the two women who demand a return on their emotional investment—their pupils have to love and unquestioningly obey. The kids sense that and unconsciously resent it. Yeah, all worked out. Ive been jogging up Mount Coot-Tha several times a week to keep fit, and theres a large commercial dumpster at a building site thatll be ideal. Ill just blend in with the other lunchtime joggers and no onell take any notice. <a href=https://gobidesserts.wordpress.com>buy cake online</a> Then why are you going away with her? Youre doing so well at school. When Mort arrived, Fystie had for the first time in his life a real friend, and Leo was relieved to once again hear the chortling laughter of his son. Mort scoured the local library and brought home whatever books Fystie asked for and they read them together, played board games, went exploring the local area, down to the drain, the small park and sometimes even as far as the beach.