要完成这个功能你可以用一个API函数,GetKeyState() 打个比方说你要判断“A”这个键的状态用VB的代码可以这样写 dim result as long dim keycodenu as long keycodenu =ascii(A) result =GetKeyState(keycodenu) if result =1 then msgbox"‘A键处于被按下状态’",vbokonly,"The state of the specified key" else msgbox"'A未被按下'",vbokonly,"The state of the specified key" end if 不知道对不对希望对你有帮助
Option Explicit Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Long Private Sub Form_Load() Timer1.Interval = 10: Timer1.Enabled = True End SubPrivate Sub Timer1_Timer() If GetAsyncKeyState(vbKeyF1) Then Me.Caption = "F1 被按下了" If GetAsyncKeyState(vbKeyF2) Then Me.Caption = "F2 被按下了" If GetAsyncKeyState(vbKeyF3) Then Me.Caption = "F3 被按下了" End Sub
打个比方说你要判断“A”这个键的状态用VB的代码可以这样写
dim result as long
dim keycodenu as long
keycodenu =ascii(A)
result =GetKeyState(keycodenu)
if result =1 then
msgbox"‘A键处于被按下状态’",vbokonly,"The state of the specified key"
else
msgbox"'A未被按下'",vbokonly,"The state of the specified key"
end if
不知道对不对希望对你有帮助
http://www.m5home.com/blog/article.asp?id=183
http://blog.csdn.net/Modest/archive/2006/10/21/1344213.aspx
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Long
Private Sub Form_Load()
Timer1.Interval = 10: Timer1.Enabled = True
End SubPrivate Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyF1) Then Me.Caption = "F1 被按下了"
If GetAsyncKeyState(vbKeyF2) Then Me.Caption = "F2 被按下了"
If GetAsyncKeyState(vbKeyF3) Then Me.Caption = "F3 被按下了"
End Sub