VB代码中KeyAscii具体是怎么用的,是什么意思?

下面有一段代码:Privatenbsp;Subnbsp;Text1_KeyPressnbsp;(KeyAsciinbsp;Asnbsp;Integer)nbsp;nbsp... 下面有一段代码:Privatenbsp;Subnbsp;Text1_KeyPressnbsp;(KeyAsciinbsp;Asnbsp;Integer)nbsp;nbsp;nbsp;Charnbsp;=nbsp;Chr(KeyAscii)nbsp;nbsp;nbsp;KeyAsciinbsp;=nbsp;Asc(UCase(Char))Endnbsp;Sub是将输入的小写字母都转成大字的字母。下面:Privatenbsp;Subnbsp;Text1_KeyPress(KeyAsciinbsp;Asnbsp;Integer)nbsp;nbsp;Ifnbsp;KeyAsciinbsp;amp;lt;nbsp;Asc(0)nbsp;Ornbsp;KeyAsciinbsp;amp;gt;nbsp;Asc(9)nbsp;Thennbsp;nbsp;nbsp;nbsp;KeyAsciinbsp;=nbsp;0nbsp;nbsp;nbsp;nbsp;MsgBoxnbsp;“请输入数字“nbsp;nbsp;Endnbsp;IfEndnbsp;Sub是只能接收输入数字的代码。都有KeyAscii我想知道有关这具函数的具体用法和详细的解释谢谢了 展开
 我来答
匿名用户
2014-01-17
展开全部
keyascii表示你按下的键的代码(AScii码)可以用以下常数表示。nbsp;===========Keycodenbsp;常数nbsp;nbsp;nbsp;可在代码中的任何地方用下列常数代替实际值:常数nbsp;值nbsp;描述nbsp;vbKeyLButtonnbsp;0x1nbsp;鼠标左键nbsp;vbKeyRButtonnbsp;0x2nbsp;鼠标右键nbsp;vbKeyCancelnbsp;0x3nbsp;CANCELnbsp;键nbsp;vbKeyMButtonnbsp;0x4nbsp;鼠标中键nbsp;vbKeyBacknbsp;0x8nbsp;BACKSPACEnbsp;键nbsp;vbKeyTabnbsp;0x9nbsp;TABnbsp;键nbsp;vbKeyClearnbsp;0xCnbsp;CLEARnbsp;键nbsp;vbKeyReturnnbsp;0xDnbsp;ENTERnbsp;键nbsp;vbKeyShiftnbsp;0x10nbsp;SHIFTnbsp;键nbsp;vbKeyControlnbsp;0x11nbsp;CTRLnbsp;键nbsp;vbKeyMenunbsp;0x12nbsp;MENUnbsp;键nbsp;vbKeyPausenbsp;0x13nbsp;PAUSEnbsp;键nbsp;vbKeyCapitalnbsp;0x14nbsp;CAPSnbsp;LOCKnbsp;键nbsp;vbKeyEscapenbsp;0x1Bnbsp;ESCnbsp;键nbsp;vbKeySpacenbsp;0x20nbsp;SPACEBARnbsp;键nbsp;vbKeyPageUpnbsp;0x21nbsp;PAGEnbsp;UPnbsp;键nbsp;vbKeyPageDownnbsp;0x22nbsp;PAGEnbsp;DOWNnbsp;键nbsp;vbKeyEndnbsp;0x23nbsp;ENDnbsp;键nbsp;vbKeyHomenbsp;0x24nbsp;HOMEnbsp;键nbsp;vbKeyLeftnbsp;0x25nbsp;LEFTnbsp;ARROWnbsp;键nbsp;vbKeyUpnbsp;0x26nbsp;UPnbsp;ARROWnbsp;键nbsp;vbKeyRightnbsp;0x27nbsp;RIGHTnbsp;ARROWnbsp;键nbsp;vbKeyDownnbsp;0x28nbsp;DOWNnbsp;ARROWnbsp;键nbsp;vbKeySelectnbsp;0x29nbsp;SELECTnbsp;键nbsp;vbKeyPrintnbsp;0x2Anbsp;PRINTnbsp;SCREENnbsp;键nbsp;vbKeyExecutenbsp;0x2Bnbsp;EXECUTEnbsp;键nbsp;vbKeySnapshotnbsp;0x2Cnbsp;SNAPSHOTnbsp;键nbsp;vbKeyInsertnbsp;0x2Dnbsp;INSERTnbsp;键nbsp;vbKeyDeletenbsp;0x2Enbsp;DELETEnbsp;键nbsp;vbKeyHelpnbsp;0x2Fnbsp;HELPnbsp;键nbsp;vbKeyNumlocknbsp;0x90nbsp;NUMnbsp;LOCKnbsp;键nbsp;Anbsp;至nbsp;Znbsp;键与nbsp;Anbsp;–nbsp;Znbsp;字母的nbsp;ASCIInbsp;码相同:常数nbsp;值nbsp;描述nbsp;vbKeyAnbsp;65nbsp;Anbsp;键nbsp;vbKeyBnbsp;66nbsp;Bnbsp;键nbsp;vbKeyCnbsp;67nbsp;Cnbsp;键nbsp;vbKeyDnbsp;68nbsp;Dnbsp;键nbsp;vbKeyEnbsp;69nbsp;Enbsp;键nbsp;vbKeyFnbsp;70nbsp;Fnbsp;键nbsp;vbKeyGnbsp;71nbsp;Gnbsp;键nbsp;vbKeyHnbsp;72nbsp;Hnbsp;键nbsp;vbKeyInbsp;73nbsp;Inbsp;键nbsp;vbKeyJnbsp;74nbsp;Jnbsp;键nbsp;vbKeyKnbsp;75nbsp;Knbsp;键nbsp;vbKeyLnbsp;76nbsp;Lnbsp;键nbsp;vbKeyMnbsp;77nbsp;Mnbsp;键nbsp;vbKeyNnbsp;78nbsp;Nnbsp;键nbsp;vbKeyOnbsp;79nbsp;Onbsp;键nbsp;vbKeyPnbsp;80nbsp;Pnbsp;键nbsp;vbKeyQnbsp;81nbsp;Qnbsp;键nbsp;vbKeyRnbsp;82nbsp;Rnbsp;键nbsp;vbKeySnbsp;83nbsp;Snbsp;键nbsp;vbKeyTnbsp;84nbsp;Tnbsp;键nbsp;vbKeyUnbsp;85nbsp;Unbsp;键nbsp;vbKeyVnbsp;86nbsp;Vnbsp;键nbsp;vbKeyWnbsp;87nbsp;Wnbsp;键nbsp;vbKeyXnbsp;88nbsp;Xnbsp;键nbsp;vbKeyYnbsp;89nbsp;Ynbsp;键nbsp;vbKeyZnbsp;90nbsp;Znbsp;键nbsp;0nbsp;至nbsp;9nbsp;键与数字nbsp;0nbsp;–nbsp;9nbsp;的nbsp;ASCIInbsp;码相同:常数nbsp;值nbsp;描述nbsp;vbKey0nbsp;48nbsp;0nbsp;键nbsp;vbKey1nbsp;49nbsp;1nbsp;键nbsp;vbKey2nbsp;50nbsp;2nbsp;键nbsp;vbKey3nbsp;51nbsp;3nbsp;键nbsp;vbKey4nbsp;52nbsp;4nbsp;键nbsp;vbKey5nbsp;53nbsp;5nbsp;键nbsp;vbKey6nbsp;54nbsp;6nbsp;键nbsp;vbKey7nbsp;55nbsp;7nbsp;键nbsp;vbKey8nbsp;56nbsp;8nbsp;键nbsp;vbKey9nbsp;57nbsp;9nbsp;键nbsp;下列常数代表数字键盘上的键:常数nbsp;值nbsp;描述nbsp;vbKeyNumpad0nbsp;0x60nbsp;0nbsp;键nbsp;vbKeyNumpad1nbsp;0x61nbsp;1nbsp;键nbsp;vbKeyNumpad2nbsp;0x62nbsp;2nbsp;键nbsp;vbKeyNumpad3nbsp;0x63nbsp;3nbsp;键nbsp;vbKeyNumpad4nbsp;0x64nbsp;4nbsp;键nbsp;vbKeyNumpad5nbsp;0x65nbsp;5nbsp;键nbsp;vbKeyNumpad6nbsp;0x66nbsp;6nbsp;键nbsp;vbKeyNumpad7nbsp;0x67nbsp;7nbsp;键nbsp;vbKeyNumpad8nbsp;0x68nbsp;8nbsp;键nbsp;vbKeyNumpad9nbsp;0x69nbsp;9nbsp;键nbsp;vb
暖萱紫菱
推荐于2018-03-30 · TA获得超过1.6万个赞
知道小有建树答主
回答量:2129
采纳率:93%
帮助的人:158万
展开全部
使用案例:
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条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式