Home > Software engineering >  Find a solution and bugs
Find a solution and bugs

Time:10-17

program objective: use the mouse to locate to text1. The content of the text box, the clipboard contents through the simulation of the keyboard CTR + v duplicated in text1. The content of the text box, and then switch the clipboard contents, and then use the mouse position to text2. The content of the text box, the clipboard contents through the simulation of the keyboard CTR + v reproduction to text2. Content of the text box, and then switch the clipboard contents, strange things happened, the second operation clipboard, has for the first time assignment text1. The text content will be changed to a second string to the clipboard assignment!
This is the code:

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=& amp; Move the mouse H1 '
Private Const MOUSEEVENTF_LEFTDOWN=& amp; The H2 'simulated mouse the left key press
Private Const MOUSEEVENTF_LEFTUP=& amp; H4 'simulation of mouse lift
Private Const MOUSEEVENTF_RIGHTDOWN=& amp; H8
Private Const MOUSEEVENTF_RIGHTUP=& amp; H10
Private Type POINTAPI
X As Long
Y As Long
End Type

Private Sub Command1_Click ()
The Clipboard. The Clear
Clipboard. SetText "title"


SetCursorPos 108, 44 rem mouse to TEXT1. The TEXT character fill local
REM the following code is to simulate the click of a mouse, and then simulate 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 please note the following 2 code is where bugs if not add the following two sentences, TEXT1. The TEXT was successfully assignment for the first time clipboard character channeling inside, but added later, they became the second character flee clipboard
The Clipboard. The Clear
Clipboard. SetText "content"
REM note 2 other code above is where bugs
End Sub

Private Sub Form_Load ()

End Sub

Private Sub Timer1_Timer ()
Dim a As POINTAPI
The GetCursorPos a
Label1. Caption=a.x
Label2. Caption=a.y
End Sub

CodePudding user response:

Has a solution, there is something wrong with your code

CodePudding user response:

You contacted me on wangwang, I compile modified engineering documents send you offline

CodePudding user response:

In the Call keybd_event (17, 0, 2, 0) to the DoEvents
  • Related