无忧编程_ASP.NET  / C# / PHP 程序员的软件世界

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1237|回复: 1

keybd_event使用方法及键值对应表

[复制链接]

212

主题

238

帖子

956

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
956
发表于 2016-2-11 16:05:52 | 显示全部楼层 |阅读模式
keybd_event使用方法及键值对应表:

indows提供了一个模拟键盘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);


附:常用模拟键的键值对照表(也可参考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  


windows .net(C#+MSSQL) linux(php+mysql)  
回复

使用道具 举报

212

主题

238

帖子

956

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
956
 楼主| 发表于 2016-2-11 16:07:21 | 显示全部楼层

The following table shows the symbolic constant names, hexadecimal values, and mouse or keyboard equivalents for the virtual-key codes used by the system. The codes are listed in numeric order.


Constant/valueDescription
VK_LBUTTON0x01

Left mouse button

VK_RBUTTON0x02

Right mouse button

VK_CANCEL0x03

Control-break processing

VK_MBUTTON0x04

Middle mouse button (three-button mouse)

VK_XBUTTON10x05

X1 mouse button

VK_XBUTTON20x06

X2 mouse button

-0x07

Undefined

VK_BACK0x08

BACKSPACE key

VK_TAB0x09

TAB key

-0x0A-0B

Reserved

VK_CLEAR0x0C

CLEAR key

VK_RETURN0x0D

ENTER key

-0x0E-0F

Undefined

VK_SHIFT0x10

SHIFT key

VK_CONTROL0x11

CTRL key

VK_MENU0x12

ALT key

VK_PAUSE0x13

PAUSE key

VK_CAPITAL0x14

CAPS LOCK key

VK_KANA0x15

IME Kana mode

VK_HANGUEL0x15

IME Hanguel mode (maintained for compatibility; use VK_HANGUL)

VK_HANGUL0x15

IME Hangul mode

-0x16

Undefined

VK_JUNJA0x17

IME Junja mode

VK_FINAL0x18

IME final mode

VK_HANJA0x19

IME Hanja mode

VK_KANJI0x19

IME Kanji mode

-0x1A

Undefined

VK_ESCAPE0x1B

ESC key

VK_CONVERT0x1C

IME convert

VK_NONCONVERT0x1D

IME nonconvert

VK_ACCEPT0x1E

IME accept

VK_MODECHANGE0x1F

IME mode change request

VK_SPACE0x20

SPACEBAR

VK_PRIOR0x21

PAGE UP key

VK_NEXT0x22

PAGE DOWN key

VK_END0x23

END key

VK_HOME0x24

HOME key

VK_LEFT0x25

LEFT ARROW key

VK_UP0x26

UP ARROW key

VK_RIGHT0x27

RIGHT ARROW key

VK_DOWN0x28

DOWN ARROW key

VK_SELECT0x29

SELECT key

VK_PRINT0x2A

PRINT key

VK_EXECUTE0x2B

EXECUTE key

VK_SNAPSHOT0x2C

PRINT SCREEN key

VK_INSERT0x2D

INS key

VK_DELETE0x2E

DEL key

VK_HELP0x2F

HELP key

0x30

0 key

0x31

1 key

0x32

2 key

0x33

3 key

0x34

4 key

0x35

5 key

0x36

6 key

0x37

7 key

0x38

8 key

0x39

9 key

-0x3A-40

Undefined

0x41

A key

0x42

B key

0x43

C key

0x44

D key

0x45

E key

0x46

F key

0x47

G key

0x48

H key

0x49

I key

0x4A

J key

0x4B

K key

0x4C

L key

0x4D

M key

0x4E

N key

0x4F

O key

0x50

P key

0x51

Q key

0x52

R key

0x53

S key

0x54

T key

0x55

U key

0x56

V key

0x57

W key

0x58

X key

0x59

Y key

0x5A

Z key

VK_LWIN0x5B

Left Windows key (Natural keyboard)

VK_RWIN0x5C

Right Windows key (Natural keyboard)

VK_APPS0x5D

Applications key (Natural keyboard)

-0x5E

Reserved

VK_SLEEP0x5F

Computer Sleep key

VK_NUMPAD00x60

Numeric keypad 0 key

VK_NUMPAD10x61

Numeric keypad 1 key

VK_NUMPAD20x62

Numeric keypad 2 key

VK_NUMPAD30x63

Numeric keypad 3 key

VK_NUMPAD40x64

Numeric keypad 4 key

VK_NUMPAD50x65

Numeric keypad 5 key

VK_NUMPAD60x66

Numeric keypad 6 key

VK_NUMPAD70x67

Numeric keypad 7 key

VK_NUMPAD80x68

Numeric keypad 8 key

VK_NUMPAD90x69

Numeric keypad 9 key

VK_MULTIPLY0x6A

Multiply key

VK_ADD0x6B

Add key

VK_SEPARATOR0x6C

Separator key

VK_SUBTRACT0x6D

Subtract key

VK_DECIMAL0x6E

Decimal key

VK_DIVIDE0x6F

Divide key

VK_F10x70

F1 key

VK_F20x71

F2 key

VK_F30x72

F3 key

VK_F40x73

F4 key

VK_F50x74

F5 key

VK_F60x75

F6 key

VK_F70x76

F7 key

VK_F80x77

F8 key

VK_F90x78

F9 key

VK_F100x79

F10 key

VK_F110x7A

F11 key

VK_F120x7B

F12 key

VK_F130x7C

F13 key

VK_F140x7D

F14 key

VK_F150x7E

F15 key

VK_F160x7F

F16 key

VK_F170x80

F17 key

VK_F180x81

F18 key

VK_F190x82

F19 key

VK_F200x83

F20 key

VK_F210x84

F21 key

VK_F220x85

F22 key

VK_F230x86

F23 key

VK_F240x87

F24 key

-0x88-8F

Unassigned

VK_NUMLOCK0x90

NUM LOCK key

VK_SCROLL0x91

SCROLL LOCK key

0x92-96

OEM specific

-0x97-9F

Unassigned

VK_LSHIFT0xA0

Left SHIFT key

VK_RSHIFT0xA1

Right SHIFT key

VK_LCONTROL0xA2

Left CONTROL key

VK_RCONTROL0xA3

Right CONTROL key

VK_LMENU0xA4

Left MENU key

VK_RMENU0xA5

Right MENU key

VK_BROWSER_BACK0xA6

Browser Back key

VK_BROWSER_FORWARD0xA7

Browser Forward key

VK_BROWSER_REFRESH0xA8

Browser Refresh key

VK_BROWSER_STOP0xA9

Browser Stop key

VK_BROWSER_SEARCH0xAA

Browser Search key

VK_BROWSER_FAVORITES0xAB

Browser Favorites key

VK_BROWSER_HOME0xAC

Browser Start and Home key

VK_VOLUME_MUTE0xAD

Volume Mute key

VK_VOLUME_DOWN0xAE

Volume Down key

VK_VOLUME_UP0xAF

Volume Up key

VK_MEDIA_NEXT_TRACK0xB0

Next Track key

VK_MEDIA_PREV_TRACK0xB1

Previous Track key

VK_MEDIA_STOP0xB2

Stop Media key

VK_MEDIA_PLAY_PAUSE0xB3

Play/Pause Media key

VK_LAUNCH_MAIL0xB4

Start Mail key

VK_LAUNCH_MEDIA_SELECT0xB5

Select Media key

VK_LAUNCH_APP10xB6

Start Application 1 key

VK_LAUNCH_APP20xB7

Start Application 2 key

-0xB8-B9

Reserved

VK_OEM_10xBA

Used for miscellaneous characters; it can vary by keyboard.

For the US standard keyboard, the ';:' key

VK_OEM_PLUS0xBB

For any country/region, the '+' key

VK_OEM_COMMA0xBC

For any country/region, the ',' key

VK_OEM_MINUS0xBD

For any country/region, the '-' key

VK_OEM_PERIOD0xBE

For any country/region, the '.' key

VK_OEM_20xBF

Used for miscellaneous characters; it can vary by keyboard.

For the US standard keyboard, the '/?' key

VK_OEM_30xC0

Used for miscellaneous characters; it can vary by keyboard.

For the US standard keyboard, the '`~' key

-0xC1-D7

Reserved

-0xD8-DA

Unassigned

VK_OEM_40xDB

Used for miscellaneous characters; it can vary by keyboard.

For the US standard keyboard, the '[{' key

VK_OEM_50xDC

Used for miscellaneous characters; it can vary by keyboard.

For the US standard keyboard, the '\|' key

VK_OEM_60xDD

Used for miscellaneous characters; it can vary by keyboard.

For the US standard keyboard, the ']}' key

VK_OEM_70xDE

Used for miscellaneous characters; it can vary by keyboard.

For the US standard keyboard, the 'single-quote/double-quote' key

VK_OEM_80xDF

Used for miscellaneous characters; it can vary by keyboard.

-0xE0

Reserved

0xE1

OEM specific

VK_OEM_1020xE2

Either the angle bracket key or the backslash key on the RT 102-key keyboard

0xE3-E4

OEM specific

VK_PROCESSKEY0xE5

IME PROCESS key

0xE6

OEM specific

VK_PACKET0xE7

Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, andWM_KEYUP

-0xE8

Unassigned

0xE9-F5

OEM specific

VK_ATTN0xF6

Attn key

VK_CRSEL0xF7

CrSel key

VK_EXSEL0xF8

ExSel key

VK_EREOF0xF9

Erase EOF key

VK_PLAY0xFA

Play key

VK_ZOOM0xFB

Zoom key

VK_NONAME0xFC

Reserved

VK_PA10xFD

PA1 key

VK_OEM_CLEAR0xFE

Clear key


windows .net(C#+MSSQL) linux(php+mysql)  
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|软件编程 Inc.  

GMT+8, 2017-7-27 10:32 , Processed in 0.189000 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表