SendInput

Résolu
cs_sergiooi Messages postés 53 Date d'inscription vendredi 6 octobre 2006 Statut Membre Dernière intervention 7 octobre 2009 - 28 nov. 2008 à 04:31
cs_sergiooi Messages postés 53 Date d'inscription vendredi 6 octobre 2006 Statut Membre Dernière intervention 7 octobre 2009 - 2 déc. 2008 à 18:50
Salut Tous!! J'aimerais avoir des infos sur l'api SendInput pour faire en sorte que losque je click sur le bouton droit de ma souris, la souris ne peux plus bouger tant que je n'aurrai pas reclicker sur le bouton droit de ma souris.
Pour faire cela, je dois pouvoir créer un mouvement de souris A UN ENDROIT PRÉCIS car j'ai remarqué que les coordonnées que j'ai entrer sont ajoutés au coordonnées actuelles de ma souris.

Ya ti quelqun qui peux m'aider??

Merci
A voir également:

10 réponses

cs_sergiooi Messages postés 53 Date d'inscription vendredi 6 octobre 2006 Statut Membre Dernière intervention 7 octobre 2009
2 déc. 2008 à 18:46
yen as plus de probleme, j'ai trouvé.


Merci!
3
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
28 nov. 2008 à 07:27
regarde la doc :

http://msdn.microsoft.com/en-us/library/ms646310.aspx

c'est moins hasardeux que de 'remarquer que'...

ca evite d'envoyer n'importe quel flag:
http://msdn.microsoft.com/en-us/library/ms646273(VS.85).aspx
0
cs_sergiooi Messages postés 53 Date d'inscription vendredi 6 octobre 2006 Statut Membre Dernière intervention 7 octobre 2009
30 nov. 2008 à 04:59
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!
0
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
30 nov. 2008 à 08:17
plein de maladresses..

xWait a remplacer par l'API Sleep
prendre l'habitude d'ecrire:
MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_MOVE
et non
MOUSEEVENTF_ABSOLUTE + MOUSEEVENTF_MOVE

...
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
30 nov. 2008 à 08:30
Option Explicit

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function ClipCursor Lib "user32.dll" (ByRef lpRect As Any) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Public Function Check_Mouse_State() As Boolean
If (GetAsyncKeyState(2) And &H8000) = &H8000 Then
Check_Mouse_State = True
End If
End Function

Private Sub Form_Load()
Dim tR As RECT
With tR
.Left = ScaleX(Screen.Width / 2, vbTwips, vbPixels)
.Top = ScaleY(Screen.Height / 2, vbTwips, vbPixels)
.Right = .Left + 1
.Bottom = .Top + 1
End With
ClipCursor tR
Do Until Check_Mouse_State
DoEvents
Loop
ClipCursor ByVal 0&
End Sub
Option Explicit

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function ClipCursor Lib "user32.dll" (ByRef lpRect As Any) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Public Function Check_Mouse_State() As Boolean
If (GetAsyncKeyState(2) And &H8000) = &H8000 Then
Check_Mouse_State = True
End If
End Function

Private Sub Form_Load()
Dim tR As RECT
With tR
.Left = ScaleX(Screen.Width / 2, vbTwips, vbPixels)
.Top = ScaleY(Screen.Height / 2, vbTwips, vbPixels)
.Right = .Left + 1
.Bottom = .Top + 1
End With
ClipCursor tR
Do Until Check_Mouse_State
DoEvents
Loop
ClipCursor ByVal 0&
End Sub
0
cs_sergiooi Messages postés 53 Date d'inscription vendredi 6 octobre 2006 Statut Membre Dernière intervention 7 octobre 2009
1 déc. 2008 à 05:27
Merci! ca marche! mais le titre du sujet est sendinput, non? je vais quand meme essayer si ca marche dans mon jeu . C'est vrai que c'est plus clair avec fonction check_mouse_state , merci.
0
cs_sergiooi Messages postés 53 Date d'inscription vendredi 6 octobre 2006 Statut Membre Dernière intervention 7 octobre 2009
1 déc. 2008 à 05:37
Resalut. et non, ca ne marche pas dans mon jeu. :( ya vraiment que sendinput qui marche pour moi. Merci encore :)
0
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
1 déc. 2008 à 06:10
"mais le titre du sujet est sendinput, non?"

ouais, enfin, tu connais ton besoin, pas la solution technique...

parles nous un peu plus de ce jeu...
si on sais sur quoi tu bosses, de nouvelles voies s'ouvriront surement
0
cs_sergiooi Messages postés 53 Date d'inscription vendredi 6 octobre 2006 Statut Membre Dernière intervention 7 octobre 2009
1 déc. 2008 à 06:55
Ouais désolé... mais  sendinput fonctionne sur mon jeu, je l'ai essayé. La seule chose que je n'arrive pas à faire, c'est de bouger ma souris avec sendinput à une position spécifique de mon écran, je réussi à faire bouger mais pas au bonnes coordonnées ... (je suis débutant alors...XD) dans ce bout de code:

Mes apis:

Option ExplicitPrivate 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

Mes constantes:
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

Mes type:

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

Et ici dans ma procédure(ex:. Form_Load):

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

Load the information needed to synthesize pressing the left mouse button.
    mouseevent.dx = 512    
    mouseevent.dy = 384
    mouseevent.mouseData = 0 ' not needed
    mouseevent.dwFlags = MOUSEEVENTF_ABSOLUTE Or 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

Comment dois-je m'y prendre??? Aidez moi quequn!! lol SVP
Merci de ton temps et ton aide!! :) :)
0
cs_sergiooi Messages postés 53 Date d'inscription vendredi 6 octobre 2006 Statut Membre Dernière intervention 7 octobre 2009
2 déc. 2008 à 18:50
Et en gros ca donné ca:

Mes apis:

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






Mes constantes:
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






Mes type:


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



Et ici dans ma procédure(ex:. Form_Load):



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 DestX as Long , DestY as Long



DestX = 512
DestY = 384
DestX = DestX * 65535 / Screen.Width * Screen.TwipsPerPixelX
DestY = DestY * 65535 / Screen.Height * Screen.TwipsPerPixelY


Load the information needed to synthesize pressing the left mouse button.
    mouseevent.dx = DestX    
    mouseevent.dy = DestY    mouseevent.mouseData = 0 ' not needed
    mouseevent.dwFlags = MOUSEEVENTF_ABSOLUTE Or 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
0
Rejoignez-nous