Salut Renfieldet les autres. Connais-tu cette fonction(sendinput) car je n'arrive pas a faire comme je le voudrais, cet à dire de faire bouger la souris au centre de mon écran(1024/768 pix)donc 512/384 non? voilà mon code:
Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long, pInputs As INPUT_TYPE, ByVal cbSize As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
'Les bouton de la souris
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Function GetLastError Lib "kernel32.dll" () As Long
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" _
(ByVal Action As Long, _
ByVal Param1 As Long, _
ByVal Param2 As Any, _
ByVal MaJProfil As Long) As Long
Const SPI_SETMOUSESPEED = 113
Private Const MOUSEEVENTF_ABSOLUTE = &H8000 ' absolute move 32768
Private Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down 2
Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up 4
Private Const MOUSEEVENTF_MIDDLEDOWN = &H20 ' middle button down 32
Private Const MOUSEEVENTF_MIDDLEUP = &H40 ' middle button up 64
Private Const MOUSEEVENTF_MOVE = &H1 ' mouse move 1
Private Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down 8
Private Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up 16
Private Const INPUT_MOUSE = 0
Private Const INPUT_KEYBOARD = 1
Private Const INPUT_HARDWARE = 2
Private Type POINTAPI
X As Long
Y As Long
End Type
'gets position and size of window relative to the parent
Declare Function GetWindowRect Lib "user32" _
(ByVal hWnd As Long, lpRect As RECT) As Long
Type MOUSEINPUT
dx As Long
dy As Long
mouseData As Long
dwFlags As Long
dwtime As Long
dwExtraInfo As Long
End Type
Type INPUT_TYPE
dwType As Long
xi(0 To 23) As Byte
End Type
Dim Click
Dim ClickGauche As Integer
Dim ClickDroit As Integer
Dim ClickMilieu As Integer
Public Left_Click As Boolean
Public Right_Click As Boolean
'fonction "Pause"
Public Sub xWait(ByVal MilsecToWait As Long)
Dim lngEndingTime As Long
lngEndingTime = GetTickCount() + (MilsecToWait)
Do While GetTickCount() < lngEndingTime
DoEvents
Loop
End Sub
Public Function Move_Mouse(XCoord As Long, YCoord As Long)
Dim intX As Integer
Dim inputevents(0 To 1) As INPUT_TYPE ' holds information about each event
Dim mouseevent As MOUSEINPUT ' temporarily hold mouse input info
Dim Speed As Long
Do Until Right_Click = False
Check_Mouse_State
' Load the information needed to synthesize pressing the left mouse button.
mouseevent.dx = XCoords
mouseevent.dy = YCoords
mouseevent.mouseData = 0 ' not needed
mouseevent.dwFlags = MOUSEEVENTF_ABSOLUTE + MOUSEEVENTF_MOVE ' move mouse
mouseevent.dwtime = 0 ' use the default
mouseevent.dwExtraInfo = 0 ' not needed
' Copy the structure into the input array's buffer.
inputevents(0).dwType = INPUT_MOUSE ' mouse input
CopyMemory inputevents(0).xi(0), mouseevent, Len(mouseevent)
' Now that all the information for the 2 input events has been placed
' into the array, finally send it into the input stream.
intX = SendInput(2, inputevents(0), Len(inputevents(0))) ' place the events into the stream
DoEvents
xWait 10
Check_Mouse_State
Loop
End Function
Public Sub Check_Mouse_State()
Dim pos As POINTAPI
GetCursorPos pos
Form1.Caption = "X : " & pos.X & " /Y : " & pos.Y
'dit quelle boutton de la souris a été enfoncer
Click = GetAsyncKeyState(1)
If Click = -32767 Then
Left_Click = True
If Right_Click = True Then
Right_Click = False
End If
End If
Click = GetAsyncKeyState(2)
If Click = -32767 Then
If Right_Click = False Then
GetCursorPos pos
Mouse_PosX = pos.X
Mouse_PosY = pos.Y
Right_Click = True
Calculate_Coords
Move_Mouse pos.X, pos.Y
ElseIf Right_Click = True Then
Right_Click = False
End If
End If
Click = GetAsyncKeyState(vbMiddleButton)
If Click = -32767 Then
End If
End Sub
Pourrais-je avoir un tit exemple pour faire bouger ma souris avec sendinput?
je sais que c'est dans mon 'Move_Mouse' le probleme mais je n'y arrive pas...
Et surtout, merci à tous!