VB如何实现点击按狃,键盘按下F9
3个回答
展开全部
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 495
Left = 1560
TabIndex = 0
Top = 1320
Width = 1215
End
Begin VB.Timer Timer1
Left = 4080
Top = 480
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'用来模拟按键
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal Scan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
'用来检测按键
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Command1_Click()
Call keybd_event(vbKeyF9, 0, 0, 0) '模拟按下F9
Call keybd_event(vbKeyF9, 0, &H2, 0) '模拟弹起F9
End Sub
Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyF9) Then
MsgBox "你按了F9键!"
End If
End Sub
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3090
ClientLeft = 60
ClientTop = 450
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3090
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 495
Left = 1560
TabIndex = 0
Top = 1320
Width = 1215
End
Begin VB.Timer Timer1
Left = 4080
Top = 480
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'用来模拟按键
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal Scan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
'用来检测按键
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Command1_Click()
Call keybd_event(vbKeyF9, 0, 0, 0) '模拟按下F9
Call keybd_event(vbKeyF9, 0, &H2, 0) '模拟弹起F9
End Sub
Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyF9) Then
MsgBox "你按了F9键!"
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
SendKeys "{F9}"
End Sub
SendKeys "{F9}"
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询