vb 程序检测按键
弹出所按下键(使用keydown事件)
语法格式为:
sub object_keydown(keycode as integer,shift as integer)
例:
private sub form_keydown(keycode as integer, shift as integer) if keycode = vbkeyup then msgbox "您按了上键!" elseif keycode = vbkeydown then msgbox "您按了下键!" elseif keycode = vbkeyleft then msgbox "您按了左键!" elseif keycode = vbkeyright then msgbox "您按了右键!" end if end sub
依此类推,可以设置为其键值
下面提供vb中的各个按键常量!
keycode 常数
可在代码中的任何地方用下列常数代替实际值:
常数 值 描述
vbkeylbutton 0x1 鼠标左键
vbkeyrbutton 0x2 鼠标右键
vbkeycancel 0x3 cancel 键
vbkeymbutton 0x4 鼠标中键
vbkeyback 0x8 backspace 键
vbkeytab 0x9 tab 键
vbkeyclear 0xc clear 键
vbkeyreturn 0xd enter 键
vbkeyshift 0x10 shift 键
vbkeycontrol 0x11 ctrl 键
vbkeymenu 0x12 menu 键
vbkeypause 0x13 pause 键
vbkeycapital 0x14 caps lock 键
vbkeyescape 0x1b esc 键
vbkeyspace 0x20 spacebar 键
vbkeypageup 0x21 page up 键
vbkeypagedown 0x22 page down 键
vbkeyend 0x23 end 键
vbkeyhome 0x24 home 键
vbkeyleft 0x25 left arrow 键
vbkeyup 0x26 up arrow 键
vbkeyright 0x27 right arrow 键
vbkeydown 0x28 down arrow 键
vbkeyselect 0x29 select 键
vbkeyprint 0x2a print screen 键
vbkeyexecute 0x2b execute 键
vbkeysnapshot 0x2c snapshot 键
vbkeyinsert 0x2d insert 键
vbkeydelete 0x2e delete 键
vbkeyhelp 0x2f help 键
vbkeynumlock 0x90 num lock 键
a 至 z 键与 a – z 字母的 ascii 码相同:
常数 值 描述
vbkeya 65 a 键
vbkeyb 66 b 键
vbkeyc 67 c 键
vbkeyd 68 d 键
vbkeye 69 e 键
vbkeyf 70 f 键
vbkeyg 71 g 键
vbkeyh 72 h 键
vbkeyi 73 i 键
vbkeyj 74 j 键
vbkeyk 75 k 键
vbkeyl 76 l 键
vbkeym 77 m 键
vbkeyn 78 n 键
vbkeyo 79 o 键
vbkeyp 80 p 键
vbkeyq 81 q 键
vbkeyr 82 r 键
vbkeys 83 s 键
vbkeyt 84 t 键
vbkeyu 85 u 键
vbkeyv 86 v 键
vbkeyw 87 w 键
vbkeyx 88 x 键
vbkeyy 89 y 键
vbkeyz 90 z 键 0 至 9 键与数字 0 – 9 的 ascii 码相同:
常数 值 描述
vbkey0 48 0 键
vbkey1 49 1 键
vbkey2 50 2 键
vbkey3 51 3 键
vbkey4 52 4 键
vbkey5 53 5 键
vbkey6 54 6 键
vbkey7 55 7 键
vbkey8 56 8 键
vbkey9 57 9 键
下列常数代表数字键盘上的键:
常数 值 描述
vbkeynumpad0 0x60 0 键
vbkeynumpad1 0x61 1 键
vbkeynumpad2 0x62 2 键
vbkeynumpad3 0x63 3 键
vbkeynumpad4 0x64 4 键
vbkeynumpad5 0x65 5 键
vbkeynumpad6 0x66 6 键
vbkeynumpad7 0x67 7 键
vbkeynumpad8 0x68 8 键
vbkeynumpad9 0x69 9 键
vbkeymultiply 0x6a multiplication sign (*) 键
vbkeyadd 0x6b plus sign ( ) 键
vbkeyseparator 0x6c enter 键
vbkeysubtract 0x6d minus sign (-) 键
vbkeydecimal 0x6e decimal point (.) 键
vbkeydivide 0x6f division sign (/) 键
下列常数代表功能键:
常数 值 描述
vbkeyf1 0x70 f1 键
vbkeyf2 0x71 f2 键
vbkeyf3 0x72 f3 键
vbkeyf4 0x73 f4 键
vbkeyf5 0x74 f5 键
vbkeyf6 0x75 f6 键
vbkeyf7 0x76 f7 键
vbkeyf8 0x77 f8 键
vbkeyf9 0x78 f9 键
vbkeyf10 0x79 f10 键
vbkeyf11 0x7a f11 键
vbkeyf12 0x7b f12 键
vbkeyf13 0x7c f13 键
vbkeyf14 0x7d f14 键
vbkeyf15 0x7e f15 键
vbkeyf16 0x7f f16 键
目前评论:0