Quelqu'un pourrait-il m'indiquer le moyen de g=E9n=E9rer un=20
clic souris =E0 partir du code VB, comme par exemple lorsque=20
l'on utilise la commande "Sendkeys" pour envoyer une=20
touche clavier =E0 une application.
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
François Picalausa
Bonjour/soir,
c'est faisable à l'aide de l'API mouse_event. Voici un exemple: Option Explicit
Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up Private Const MOUSEEVENTF_ABSOLUTE = &H8000 Private Const MOUSEEVENTF_MOVE = &H1
Private Type POINTAPI X As Long Y As Long End Type
Private Declare Function GetCursorPos _ Lib "user32" _ ( _ lpPoint As POINTAPI _ ) _ 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 Sub DoClick() Dim ptaCursorPos As POINTAPI
GetCursorPos ptaCursorPos mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_ABSOLUTE, _ ptaCursorPos.X, _ ptaCursorPos.Y, _ 0&, _ 0& mouse_event MOUSEEVENTF_LEFTUP Or MOUSEEVENTF_ABSOLUTE, _ ptaCursorPos.X, _ ptaCursorPos.Y, _ 0&, _ 0& End Sub
Private Sub DoMoveRelative(X As Long, Y As Long) mouse_event MOUSEEVENTF_MOVE, _ X, _ Y, _ 0&, _ 0& End Sub
Private Sub DoMoveAbsolute(X As Long, Y As Long) 'Absolute data is specified as the mouse's actual x-coordinate; 'relative data is specified as the number of mickeys moved. 'A mickey is the amount that a mouse has to move for it to report that it has moved. mouse_event MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE, _ X, _ Y, _ 0&, _ 0& End Sub
Private Sub Command1_Click() 'Déplace le curseur de 50,50 DoMoveRelative 50, 50 'Click DoClick End Sub
"mimi" a écrit dans le message de news:330e01c3fd45$08531820$
Bonjour à tous,
Quelqu'un pourrait-il m'indiquer le moyen de générer un clic souris à partir du code VB, comme par exemple lorsque l'on utilise la commande "Sendkeys" pour envoyer une touche clavier à une application.
Merci et bonne journée Mimi
Bonjour/soir,
c'est faisable à l'aide de l'API mouse_event.
Voici un exemple:
Option Explicit
Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up
Private Const MOUSEEVENTF_ABSOLUTE = &H8000
Private Const MOUSEEVENTF_MOVE = &H1
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetCursorPos _
Lib "user32" _
( _
lpPoint As POINTAPI _
) _
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 Sub DoClick()
Dim ptaCursorPos As POINTAPI
GetCursorPos ptaCursorPos
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_ABSOLUTE, _
ptaCursorPos.X, _
ptaCursorPos.Y, _
0&, _
0&
mouse_event MOUSEEVENTF_LEFTUP Or MOUSEEVENTF_ABSOLUTE, _
ptaCursorPos.X, _
ptaCursorPos.Y, _
0&, _
0&
End Sub
Private Sub DoMoveRelative(X As Long, Y As Long)
mouse_event MOUSEEVENTF_MOVE, _
X, _
Y, _
0&, _
0&
End Sub
Private Sub DoMoveAbsolute(X As Long, Y As Long)
'Absolute data is specified as the mouse's actual x-coordinate;
'relative data is specified as the number of mickeys moved.
'A mickey is the amount that a mouse has to move for it to report that
it has moved.
mouse_event MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE, _
X, _
Y, _
0&, _
0&
End Sub
Private Sub Command1_Click()
'Déplace le curseur de 50,50
DoMoveRelative 50, 50
'Click
DoClick
End Sub
"mimi" <michel.gandner@chello.fr> a écrit dans le message de
news:330e01c3fd45$08531820$a401280a@phx.gbl
Bonjour à tous,
Quelqu'un pourrait-il m'indiquer le moyen de générer un
clic souris à partir du code VB, comme par exemple lorsque
l'on utilise la commande "Sendkeys" pour envoyer une
touche clavier à une application.
c'est faisable à l'aide de l'API mouse_event. Voici un exemple: Option Explicit
Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up Private Const MOUSEEVENTF_ABSOLUTE = &H8000 Private Const MOUSEEVENTF_MOVE = &H1
Private Type POINTAPI X As Long Y As Long End Type
Private Declare Function GetCursorPos _ Lib "user32" _ ( _ lpPoint As POINTAPI _ ) _ 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 Sub DoClick() Dim ptaCursorPos As POINTAPI
GetCursorPos ptaCursorPos mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_ABSOLUTE, _ ptaCursorPos.X, _ ptaCursorPos.Y, _ 0&, _ 0& mouse_event MOUSEEVENTF_LEFTUP Or MOUSEEVENTF_ABSOLUTE, _ ptaCursorPos.X, _ ptaCursorPos.Y, _ 0&, _ 0& End Sub
Private Sub DoMoveRelative(X As Long, Y As Long) mouse_event MOUSEEVENTF_MOVE, _ X, _ Y, _ 0&, _ 0& End Sub
Private Sub DoMoveAbsolute(X As Long, Y As Long) 'Absolute data is specified as the mouse's actual x-coordinate; 'relative data is specified as the number of mickeys moved. 'A mickey is the amount that a mouse has to move for it to report that it has moved. mouse_event MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE, _ X, _ Y, _ 0&, _ 0& End Sub
Private Sub Command1_Click() 'Déplace le curseur de 50,50 DoMoveRelative 50, 50 'Click DoClick End Sub
"mimi" a écrit dans le message de news:330e01c3fd45$08531820$
Bonjour à tous,
Quelqu'un pourrait-il m'indiquer le moyen de générer un clic souris à partir du code VB, comme par exemple lorsque l'on utilise la commande "Sendkeys" pour envoyer une touche clavier à une application.
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 Declare Function GetDeviceCaps _ Lib "gdi32" _ ( _ ByVal hdc As Long, _ ByVal nIndex As Long _ ) _ As Long
Const HORZRES = 8 Const VERTRES = 10
Private Sub DoMoveAbsolute(X As Long, Y As Long) 'Absolute data is specified as the mouse's actual x-coordinate; 'relative data is specified as the number of mickeys moved. 'A mickey is the amount that a mouse has to move for it to report that 'it has moved. mouse_event MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE, _ X, _ Y, _ 0&, _ 0& End Sub
Private Sub Command1_Click() 'If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized 'absolute coordinates between 0 and 65,535. The event procedure maps these 'coordinates onto the display surface. Coordinate (0,0) maps onto the upper-left 'corner of the display surface, (65535,65535) maps onto the lower-right corner. Const COORDINATES_MAX As Long = 65535
'On va tenter de positionner la souris en 100,50 (pixels) Const PosX As Long = 100 Const PosY As Long = 50
Celà ne devrait pas onctionner si a définit une accélération du curseur. Pour plus d'informations, voir les remarques de la fiche sur mouse_event: http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/userinput/mouseinput/mouseinputreference/mouseinputfunctions/mouse_event.asp
Mais faire se déplacer le curseur pour clicker est aussi précis qu'un sendkeys... Je ne recommande donc pas cette méthode (sauf si on ne peut pas faire autrement.. mais on peut toujours faire autrement.. récupérer le hwnd et envoyer un WM_CLICK par exemple).
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 Declare Function GetDeviceCaps _
Lib "gdi32" _
( _
ByVal hdc As Long, _
ByVal nIndex As Long _
) _
As Long
Const HORZRES = 8
Const VERTRES = 10
Private Sub DoMoveAbsolute(X As Long, Y As Long)
'Absolute data is specified as the mouse's actual x-coordinate;
'relative data is specified as the number of mickeys moved.
'A mickey is the amount that a mouse has to move for it to report that
'it has moved.
mouse_event MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE, _
X, _
Y, _
0&, _
0&
End Sub
Private Sub Command1_Click()
'If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain
normalized
'absolute coordinates between 0 and 65,535. The event procedure maps
these
'coordinates onto the display surface. Coordinate (0,0) maps onto the
upper-left
'corner of the display surface, (65535,65535) maps onto the lower-right
corner.
Const COORDINATES_MAX As Long = 65535
'On va tenter de positionner la souris en 100,50 (pixels)
Const PosX As Long = 100
Const PosY As Long = 50
Celà ne devrait pas onctionner si a définit une accélération du curseur.
Pour plus d'informations, voir les remarques de la fiche sur mouse_event:
http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/userinput/mouseinput/mouseinputreference/mouseinputfunctions/mouse_event.asp
Mais faire se déplacer le curseur pour clicker est aussi précis qu'un
sendkeys...
Je ne recommande donc pas cette méthode (sauf si on ne peut pas faire
autrement.. mais on peut toujours faire autrement.. récupérer le hwnd et
envoyer un WM_CLICK par exemple).
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 Declare Function GetDeviceCaps _ Lib "gdi32" _ ( _ ByVal hdc As Long, _ ByVal nIndex As Long _ ) _ As Long
Const HORZRES = 8 Const VERTRES = 10
Private Sub DoMoveAbsolute(X As Long, Y As Long) 'Absolute data is specified as the mouse's actual x-coordinate; 'relative data is specified as the number of mickeys moved. 'A mickey is the amount that a mouse has to move for it to report that 'it has moved. mouse_event MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE, _ X, _ Y, _ 0&, _ 0& End Sub
Private Sub Command1_Click() 'If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized 'absolute coordinates between 0 and 65,535. The event procedure maps these 'coordinates onto the display surface. Coordinate (0,0) maps onto the upper-left 'corner of the display surface, (65535,65535) maps onto the lower-right corner. Const COORDINATES_MAX As Long = 65535
'On va tenter de positionner la souris en 100,50 (pixels) Const PosX As Long = 100 Const PosY As Long = 50
Celà ne devrait pas onctionner si a définit une accélération du curseur. Pour plus d'informations, voir les remarques de la fiche sur mouse_event: http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/userinput/mouseinput/mouseinputreference/mouseinputfunctions/mouse_event.asp
Mais faire se déplacer le curseur pour clicker est aussi précis qu'un sendkeys... Je ne recommande donc pas cette méthode (sauf si on ne peut pas faire autrement.. mais on peut toujours faire autrement.. récupérer le hwnd et envoyer un WM_CLICK par exemple).