发现一个无解的BUG求高手指点
程序目的:利用鼠标定位到text1.text内容框,把剪切板内容通过模拟键盘操作的ctr+v 复制给text1.text内容框,然后切换剪切板内容,然后利用鼠标定位到text2.text内容框,把剪切板内容通过模拟键盘操作的ctr+v 复制给text2.text内容框,然后切换剪切板内容,诡异事情发生了,第二次操作剪切板时候,第一次已经赋值的text1.text内容会被改变为,第二次给剪切板赋值的字符串!这是代码:
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
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 Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Private Const MOUSEEVENTF_MOVE = &H1 '移动鼠标
Private Const MOUSEEVENTF_LEFTDOWN = &H2 '模拟鼠标左键按下
Private Const MOUSEEVENTF_LEFTUP = &H4 '模拟鼠标左键抬起
Private Const MOUSEEVENTF_RIGHTDOWN = &H8
Private Const MOUSEEVENTF_RIGHTUP = &H10
Private Type POINTAPI
x As Long
y As Long
End Type
Private Sub Command1_Click()
Clipboard.Clear
Clipboard.SetText "标题"
SetCursorPos 108, 44 rem鼠标移动到TEXT1.TEXT字符填充地方
REM下面代码是模拟点击鼠标定位,然后模拟CTR+V
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Call keybd_event(17, 0, 0, 0)
Call keybd_event(86, 0, 0, 0)
Call keybd_event(86, 0, 2, 0)
Call keybd_event(17, 0, 2, 0)
REM 请注意下面2句代码就是出现BUG地方如果不加下面2句。TEXT1.TEXT被成功赋值为第一次剪切板里面字符窜。但是加了后,就变成了第二次剪切板里面字符窜
Clipboard.Clear
Clipboard.SetText "内容"
REM 请注意上面2句代码就是出现BUG地方
End Sub
Private Sub Form_Load()
End Sub
Private Sub Timer1_Timer()
Dim a As POINTAPI
GetCursorPos a
Label1.Caption = a.x
Label2.Caption = a.y
End Sub
有解,你代码有问题 你在旺旺上联系过我,我把修改的工程编译文件发你离线了 在Call keybd_event(17, 0, 2, 0) 下加 DoEvents
补充:VB , 基础类