vb不能用keybd_event实现复制功能
我使用以下代码,但不能实现复制,请大神指点keybd_event17,0,0,0keybd_event99,0,0,0keybd_event17,0,&H2,0keybd...
我使用以下代码,但不能实现复制,请大神指点
keybd_event 17, 0, 0, 0
keybd_event 99, 0, 0, 0
keybd_event 17, 0, &H2, 0
keybd_event 99, 0, &H2, 0
我用以下代码模拟ENTER+CTRL是成功的,怎么模拟CTRL+C就不行呢?
keybd_event 17, 0, 0, 0
keybd_event 13, 0, 0, 0
keybd_event 17, 0, KEYEVENT_KEYUP, 0
keybd_event 13, 0, KEYEVENT_KEYUP, 0 展开
keybd_event 17, 0, 0, 0
keybd_event 99, 0, 0, 0
keybd_event 17, 0, &H2, 0
keybd_event 99, 0, &H2, 0
我用以下代码模拟ENTER+CTRL是成功的,怎么模拟CTRL+C就不行呢?
keybd_event 17, 0, 0, 0
keybd_event 13, 0, 0, 0
keybd_event 17, 0, KEYEVENT_KEYUP, 0
keybd_event 13, 0, KEYEVENT_KEYUP, 0 展开
2个回答
2014-12-12
展开全部
给你一个测试通过的:
Private Declare Sub keybd_event Lib "user32" Alias "keybd_event" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
Private Sub Delay(time As Long)
Dim oldtime As Long
oldtime = GetTickCount()
If GetTickCount - oldtime < time Then
Doevents
End If
End Sub
Private Sub Copy()
Call keybd_event(17, 0, 0, 0) '//按下ctrl
Call Delay(100)
Call keybd_event(67, 0, 0, 0) '//按下c
Call Delay(100)
Call keybd_event(67, 0, 2, 0) '//松开c
Call Delay(100)
Call keybd_event(17, 0, 2, 0) '//松开ctrl
End Sub
Private Declare Sub keybd_event Lib "user32" Alias "keybd_event" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
Private Sub Delay(time As Long)
Dim oldtime As Long
oldtime = GetTickCount()
If GetTickCount - oldtime < time Then
Doevents
End If
End Sub
Private Sub Copy()
Call keybd_event(17, 0, 0, 0) '//按下ctrl
Call Delay(100)
Call keybd_event(67, 0, 0, 0) '//按下c
Call Delay(100)
Call keybd_event(67, 0, 2, 0) '//松开c
Call Delay(100)
Call keybd_event(17, 0, 2, 0) '//松开ctrl
End Sub
追问
还是不行啊,没复制的效果
追答
怎么会没有呢,我以复制TEXT1内容为例进行测试,结果成功,如图:
你可以自己测试,控件自己添加TEXT和command,代码如下:
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub Delay(time As Long)
Dim oldtime As Long
oldtime = GetTickCount()
If GetTickCount - oldtime < time Then
DoEvents
End If
End Sub
Private Sub Copy()
Call keybd_event(17, 0, 0, 0) '//按下ctrl
Call Delay(100)
Call keybd_event(67, 0, 0, 0) '//按下c
Call Delay(100)
Call keybd_event(67, 0, 2, 0) '//松开c
Call Delay(100)
Call keybd_event(17, 0, 2, 0) '//松开ctrl
End Sub
Private Sub Command1_Click()
Text1.SetFocus
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
Call Copy
MsgBox Clipboard.GetText
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询