17/09/09 12:26
dylan666
Sto cercando di emulare la pressione del tasto sinistro fuori da una form. In pratica mi servirebbe che cliccasse dentro una form web(di una pagina internet aperta sul browser) e poi facesse Ctr+A e Ctrl+C per copiarne il testo. Mi sto esetrcitando con questo codice:
Option Explicit
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const VK_0 = &H30
Private Const VK_1 = &H31
Private Const VK_2 = &H32
Private Const VK_3 = &H33
Private Const VK_LBUTTONDW As Long = &H2 'Left mouse button
Private Const VK_LBUTTONUP As Long = &H4 ' left button up
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Sub MoveMouse(x As Single, y As Single)
Dim pt As POINTAPI
pt.x = x
pt.y = y
SetCursorPos pt.x, pt.y
End Sub
Private Sub Command1_Click()
MoveMouse Text1.Text, Text2.Text
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
keybd_event VK_LBUTTONDW, 1, 0, 0
keybd_event VK_LBUTTONUP, 1, 0, 0
keybd_event VK_0, 1, 0, 0
keybd_event VK_1, 1, 0, 0
keybd_event VK_2, 1, 0, 0
keybd_event VK_3, 1, 0, 0
End Sub
[\code]
Se clicco io nella finsetra dopo vedo che scrive "123" ma il click per mettere il focus pare non funzionare. Come mai? E come faccio delle combinazioni di stasti tipo Ctrl+C?
Spiegate con chiarezza e esempi per favore perché sono agli inzi
Option Explicit
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Const VK_0 = &H30
Private Const VK_1 = &H31
Private Const VK_2 = &H32
Private Const VK_3 = &H33
Private Const VK_LBUTTONDW As Long = &H2 'Left mouse button
Private Const VK_LBUTTONUP As Long = &H4 ' left button up
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Sub MoveMouse(x As Single, y As Single)
Dim pt As POINTAPI
pt.x = x
pt.y = y
SetCursorPos pt.x, pt.y
End Sub
Private Sub Command1_Click()
MoveMouse Text1.Text, Text2.Text
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
keybd_event VK_LBUTTONDW, 1, 0, 0
keybd_event VK_LBUTTONUP, 1, 0, 0
keybd_event VK_0, 1, 0, 0
keybd_event VK_1, 1, 0, 0
keybd_event VK_2, 1, 0, 0
keybd_event VK_3, 1, 0, 0
End Sub
[\code]
Se clicco io nella finsetra dopo vedo che scrive "123" ma il click per mettere il focus pare non funzionare. Come mai? E come faccio delle combinazioni di stasti tipo Ctrl+C?
Spiegate con chiarezza e esempi per favore perché sono agli inzi
Ultima modifica effettuata da dylan666 17/09/09 12:55
aaa