当前位置:编程学习 > VB >>

vb中按键接受使用实例

求代码以熟悉vb中接受按键的方法

1.form上有一label,当你摁下方向键及wasd键时他就会动(俗称label1.left或top+-100)

2.按下alt时,她就消失了也!(俗称label1.visible=FALSE)

3.按下空格时他又回来了!(又名label1.visible=TRUE)

最主要是1,2·3顺便答了就算了(可选)

sorry,悬赏分最多加到100,不知道他们咋加的500,但我可已追加!求解

补充:都很有帅道!

/8-)P☆Z☆L童鞋的alt与空格打错了,隐藏显示不可用。

浆糊童鞋很完美

答案:Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 87 or KeyCode=119 or KeyCode=24 Then

label1.top=label1.top-100

elseif KeyCode=83 or KeyCode=115 or KeyCode=25 then

label1.top=label1.top+100

elseif KeyCode=65 or KeyCode=97 or KeyCode=27 then

label1.left=label1.left-100

elseif KeyCode=68 or KeyCode=100 or KeyCode=26 then

label1.left=label1.left+100

elseif KeyCode=164 or KeyCode=165 then

label1.visible=FALSE

elseif KeyCode=32 then

label1.visible=true

endif
End Sub

试试,我这边没有vb编译,你看看通过么?

楼上的程序有点问题

看我的

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyA
Label1.Left = Label1.Left - 10
Case vbKeyLeft
Label1.Left = Label1.Left - 10
Case vbKeyD
Label1.Left = Label1.Left + 10
Case vbKeyRight
Label1.Left = Label1.Left + 10
Case vbKeyW
Label1.Top = Label1.Top - 10
Case vbKeyUp
Label1.Top = Label1.Top - 10
Case vbKeyS
Label1.Top = Label1.Top + 10
Case vbKeyDown
Label1.Top = Label1.Top + 10
Case vbKeySpace
Label1.Visible = True
Case 18
Label1.Visible = False
End Select

End Sub

vb6.0下调试通过

附上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 键

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 键

vbKeyDelete 0x2E DELETE 键

vbKeyHelp 0x2F HELP 键

vbKeyNumlock 0x90 NUM LOCK 键

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 键

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 MULTIPLICATIONSIGN(*)键

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 键

还有疑问加我qq690080258

老兄.我可以给你注册热键的方法,你应该看看就懂了.

http://tech.ddvip.com/2009-06/1244098346122435.html

注册控件的三种简单办法.

http://www.abc188.com/info/html/chengxusheji/VB/20080224/25841.html

这里有你想要的.

上一个:SQL Server 如何与VB连接
下一个:vb使用API的问题

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,