VB代码中KeyAscii具体是怎么用的,是什么意思?
答案:4 悬赏:0
解决时间 2021-01-20 15:30
- 提问者网友:听门外雪花风
- 2021-01-19 16:16
VB代码中KeyAscii具体是怎么用的,是什么意思?
最佳答案
- 二级知识专家网友:从此江山别
- 2021-01-19 17:50
使用案例:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If Chr(KeyCode) = "A" Then Image1.Left = Image1.Left - 100
If Chr(KeyCode) = "D" Then Image1.Left = Image1.Left + 100
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) = "w" Then Image1.Top = Image1.Top - 100
If Chr(KeyAscii) = "s" Then Image1.Top = Image1.Top + 100
End Sub
例一:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Then you.Top = You.Top - 10
If KeyCode = vbKeyDown Then You.Top = You.Top + 10
If KeyCode = vbKeyleft Then you.Top = You.left - 10
If KeyCode = vbKeyright Then You.Top = You.left + 10
End Sub
例二:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 37 Then pig.Left = pig.Left - 10
If KeyCode = 38 Then pig.Top = pig.Top - 10
If KeyCode = 39 Then pig.Left = pig.Left + 10
If KeyCode = 40 Then pig.Top = pig.Top + 10
End Sub
例三:
Private Sub Form_KeyPress(KeyAscii As Integer)
if chr(keyascii)="a" then pig.Left = pig.Left - 10
if chr(keyascii)="d" then pig.Left = pig.Left + 10
if chr(keyascii)="w" then pig.top = pig.top - 10
if chr(keyascii)="s" then pig.top = pig.top + 10
end sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If Chr(KeyCode) = "A" Then Image1.Left = Image1.Left - 100
If Chr(KeyCode) = "D" Then Image1.Left = Image1.Left + 100
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) = "w" Then Image1.Top = Image1.Top - 100
If Chr(KeyAscii) = "s" Then Image1.Top = Image1.Top + 100
End Sub
例一:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Then you.Top = You.Top - 10
If KeyCode = vbKeyDown Then You.Top = You.Top + 10
If KeyCode = vbKeyleft Then you.Top = You.left - 10
If KeyCode = vbKeyright Then You.Top = You.left + 10
End Sub
例二:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 37 Then pig.Left = pig.Left - 10
If KeyCode = 38 Then pig.Top = pig.Top - 10
If KeyCode = 39 Then pig.Left = pig.Left + 10
If KeyCode = 40 Then pig.Top = pig.Top + 10
End Sub
例三:
Private Sub Form_KeyPress(KeyAscii As Integer)
if chr(keyascii)="a" then pig.Left = pig.Left - 10
if chr(keyascii)="d" then pig.Left = pig.Left + 10
if chr(keyascii)="w" then pig.top = pig.top - 10
if chr(keyascii)="s" then pig.top = pig.top + 10
end sub
全部回答
- 1楼网友:纵马山川剑自提
- 2021-01-19 21:39
KeyAscii 是一个接收键盘向程序发送按键按下时的Ascii码的变量...其实它没有什么神秘,它仅仅是一个传递的变量而已....但它有一个特别之处就是这是一个固定的变量,既不能用其它字符代替...
- 2楼网友:旧脸谱
- 2021-01-19 20:10
前面说的不对
我说个例子就打破他的说法了(汉字也有对应的ascii码,键盘没汉字吧!)
keyascii表示你按下的键后的字符代码(字符AScii码)
上面也给了例子,例子是对的!但他的说法应该改正为我的说法了!
我说个例子就打破他的说法了(汉字也有对应的ascii码,键盘没汉字吧!)
keyascii表示你按下的键后的字符代码(字符AScii码)
上面也给了例子,例子是对的!但他的说法应该改正为我的说法了!
- 3楼网友:大漠
- 2021-01-19 18:31
我暂时保留我的看法!
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯