一个简单的VB模拟按键
发布网友
发布时间:2024-03-20 18:24
我来回答
共3个回答
热心网友
时间:2024-03-22 21:50
' 建立一个窗体,窗体中含有两个名称各为“GetKey1”和“Run1”的Timer控件,并写入以下:
'------------------------------------------------------
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
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 Sub Sleep Lib "KERNEL32" (ByVal dwMilliseconds As Long)
Private Function MyHotKey(vKeyCode) As Boolean
MyHotKey = (GetAsyncKeyState(vKeyCode) < 0)
End Function
Private Sub Form_Load()
GetKey1.Interval = 50
End Sub
Private Sub GetKey1_Timer()
If MyHotKey(vbKeyF10) Then Run1.Interval = 500 '重复延时500毫秒
If MyHotKey(vbKeyF12) Then Run1.Interval = 0
End Sub
Private Sub Run1_Timer()
keybd_event vbKey1, 0, 0, 0 '按键1
Sleep 500 '延时500毫秒
keybd_event vbKeyV, 0, 0, 0 '按键V
End Sub
'------------------------------------------------------
'生成EXE应用程序运行后你会看到效果。
热心网友
时间:2024-03-22 21:51
干吗用呢??
热心网友
时间:2024-03-22 21:49
想恶作剧吗?