用VB发送组合键代码

来源:互联网 发布:淘宝怎么设置定时开售 编辑:程序博客网 时间:2024/05/16 09:14

KEYEVENTF_KEYUP=2


发送Ctrl+A键

keybd_event VK_Ctrl, MapVirtualKey(VK_Ctrl, 0), 0, 0   '按下Ctrl键
PostMessage hwnd,WM_KEYDOWN,VK_A,MakeKeyLparam(VK_A,WM_KEYDOWN)  '按下A键
Sleep 500    '延时500毫秒
PostMessage hwnd,WM_UP,VK_A,MakeKeyLparam(VK_A,WM_UP)     '释放A键
keybd_event VK_Ctrl, MapVirtualKey(VK_Ctrl, 0), KEYEVENTF_KEYUP, 0   '释放Ctrl键




发送Alt+E键
PostMessage hwnd,WM_SYSKEYDOWN,VK_E,&20120001   '按下Alt+E键,VK_E(扫描码12) ' &H20000000 为lParam 的第29位,置 1 表示 Alt 键被按下


 




WM_SYSKEYDOWN说明:


The WM_SYSKEYDOWN message is posted to the window with the keyboard focus when the user holds down the ALT key and then presses another key. It also occurs when no window currently has the keyboard focus; in this case, the WM_SYSKEYDOWN message is sent to the active window. The window that receives the message can distinguish between these two contexts by checking the context code in the lKeyData parameter.


WM_SYSKEYDOWN  
nVirtKey = (int) wParam; // virtual-key code 
lKeyData = lParam;       // key data




Parameters


nVirtKey


Value of wParam. Specifies the virtual-key code of the key being pressed.


lKeyData


Value of lParam. Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table:


Value Description
0-15 Specifies the repeat count. The value is the number of times the keystroke is repeated as a result of the user holding down the key.
16-23 Specifies the scan code. The value depends on the original equipment manufacturer (OEM).
24 Specifies whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0.
25-28 Reserved; do not use.
29 Specifies the context code. The value is 1 if the ALT key is down while the key is pressed; it is 0 if the WM_SYSKEYDOWN message is posted to the active window because no window has the keyboard focus.
30 Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is 0 if the key is up.
31 Specifies the transition state. The value is always 0 for a WM_SYSKEYDOWN message.


0-15位:指定当前消息的重复次数。其值就是用户按下该键后自动重复的次数,但是重复次数不累积 
16-23位:指定其扫描码,其值依赖于OEM厂商 
24位:指定该按键是否为扩展按键,所谓扩展按键就是Ctrl,Alt之类的,如果是扩展按键,其值为1,否则为0 
25-28位:保留字段,暂时不可用 
29位:指定按键时的上下文,其值为1时表示在按键时Alt键被按下,其值为0表示WM_SYSKEYDOWN消息因没有任何窗口有键盘焦点而被发送到当前活动窗口。 
30位:指定该按键之前的状态,其值为1时表示该消息发送前,该按键是被按下的,其值为0表示该消息发送前该按键是抬起的。 
31位:指定其转换状态,对WM_SYSKEYDOWN消息而言,其值总为0  (0表示按下,1表示释放)。 


Ctrl: $10000000
Shift:$08000000
Alt:  $20000000


Delphi键盘按键伪码


常数名称          十六进制值      十进制值          对应按键
VK_LBUTTON           01              1              鼠标的左键
VK_RBUTTON           02              2              鼠标的右键
VK-CANCEL            03              3              Contol-break 执行
VK_MBUTTON           04              4              鼠标的中键(三按键鼠标)
VK_BACK              08              8              Backspace键
VK_TAB               09              9              Tab键
VK_CLEAR             0C              12             Clear键
VK_RETURN            0D              13             Enter键
VK_SHIFT             10              16             Shift键
VK_CONTROL           11              17             Ctrl键
VK_MENU              12              18             Alt键
VK_PAUSE             13              19             Pause键
VK_CAPITAL           14              20             Caps  Lock键
VK_ESCAPE            1B              27             Ese键
VK_SPACE             20              32             Spacebar键
VK_PRIOR             21              33             Page Up键
VK_NEXT              22              34             Page Domw键
VK_END               23              35             End键
VK_HOME              24              36             Home键
VK_LEFT              25              37             LEFT ARROW 键(←)
VK_UP                26              38             UP ARROW键(↑)
VK_RIGHT             27              39             RIGHT ARROW键(→)
VK_DOWN              28              40             DOWN  ARROW键(↓)
VK_SELECT            29              41             SELECT键
VK_EXECUTE           2B              43             EXECUTE键
VK_SNAPSHOT          2C              44             Print Screen键              
VK_INSERT            2D              45             Ins键
VK_DELETE            2E              46             Del键
VK_HELP              2F              47             Help键
VK_0                 30              48             0键
VK_1                 31              49             1键
VK_2                 32              50             2键
VK_3                 33              51             3键
VK_4                 34              52             4键
VK_5                 35              53             5键
VK_6                 36              54             6键
VK_7                 37              55             7键
VK_8                 38              56             8键
VK_9                 39              57             9键
VK_A                 41              65             A键
VK_B                 42              66             B键
VK_C                 43              67             C键
VK_D                 44              68             D键
VK_E                 45              69             E键
VK_F                 46              70             F键
VK_G                 47              71             G键
VK_H                 48              72             H键
VK_I                 49              73             I键
VK_J                 4A              74             J键
VK_K                 4B              75             K键
VK_L                 4C              76             L键
VK_M                 4D              77             M键
VK_N                 4E              78             N键
VK_O                 4F              79             O键
VK_P                 50              80             P键
VK_Q                 51              81             Q键
VK_R                 52              82             R键
VK_S                 53              83             S键
VK_T                 54              84             T键
VK_U                 55              85             U键
VK_V                 56              86             V键
VK_W                 57              87             W键
VK_X                 58              88             X键
VK_Y                 59              89             Y键
VK_BZ                5A              90             Z键
VK_NUMPAD0           60              96             数字键0键
VK_NUMPAD1           61              97             数字键1键
VK_NUMPAD2           62              98             数字键2键
VK_NUMPAD3           63              99             数字键3键
VK_NUMPAD4           64              100            数字键4键
VK_NUMPAD5           65              101            数字键5键
VK_NUMPAD6           66              102            数字键6键
VK_NUMPAD7           67              103            数字键7键
VK_NUMPAD8           68              104            数字键8键
VK_NUMPAD9           69              105            数字键9键
VK_MULTIPLY          6A              106            *键
VK_ADD               6B              107            +键
VK_SEPARATOR         6C              108            Separator键
VK_SUBTRACT          6D              109            -键
VK_DECIMAL           6E              110            .键
VK_DIVIDE            6F              111            键
VK_F1                70              112            F1键
VK_F2                71              113            F2键
VK_F3                72              114            F3键
VK_F4                73              115            F4键
VK_F5                74              116            F5键
VK_F6                75              117            F6键
VK_F7                76              118            F7键
VK_F8                77              119            F8键
VK_F9                78              120            F9键
VK_F10               79              121            F10键
VK_F11               7A              122            F11键
VK_F12               7B              123            F12键
VK_NUMLOCK           90              144            Num Lock键
VK_SCROLL            91              145            Scroll Lock键
原创粉丝点击