Les Snippets

Connexion

Simulation souris

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 17/05/2009 22:10:21 et initié par Charles Racaud [Liste]
Vue : 4332
Catégorie(s) : API, Trucs & Astuces
Langage sélectionné : VB 2005
Langages dispo pour ce code :
- C# 1.x, C# 2.x, C# 3.x
- VB 2005, VB 2008, VB.NET 1.x
- VB6, VBA
- Voir tous les langages pour ce code snippet



Langage : VB.NET 1.x , VB 2005 , VB 2008
Date ajout : 17/05/2009
Posté par Charles Racaud [Liste]

'Imports System
'Imports System.Runtime.InteropServices
'Imports System.Windows.Forms

Private Const INPUT_MOUSE As Integer = 0
Private Const MOUSEEVENTF_MOVE As UInteger = &H1UI
Private Const MOUSEEVENTF_LEFTDOWN As UInteger = &H2UI
Private Const MOUSEEVENTF_LEFTUP As UInteger = &H4UI
Private Const MOUSEEVENTF_RIGHTDOWN As UInteger = &H8UI
Private Const MOUSEEVENTF_RIGHTUP As UInteger = &H10UI
Private Const MOUSEEVENTF_MIDDLEDOWN As UInteger = &H20UI
Private Const MOUSEEVENTF_MIDDLEUP As UInteger = &H40UI
Private Const MOUSEEVENTF_XDOWN As UInteger = &H80UI
Private Const MOUSEEVENTF_XUP As UInteger = &H100UI
Private Const MOUSEEVENTF_WHEEL As UInteger = &H800UI
Private Const MOUSEEVENTF_HWHEEL As UInteger = &H1000UI
Private Const MOUSEEVENTF_ABSOLUTE As UInteger = &H8000UI
Private Const XBUTTON1 As Integer = &H1UI
Private Const XBUTTON2 As Integer = &H2UI
Private Const WHEEL_DELTA As Integer = 120UI

<StructLayout(LayoutKind.Sequential)> _
Private Structure MOUSEINPUT
  Public dx As Integer
  Public dy As Integer
  Public mouseData As Integer
  Public dwFlags As UInteger
  Public time As UInteger
  Public dwExtraInfo As IntPtr
End Structure

<StructLayout(LayoutKind.Explicit)> _
Private Structure INPUT
  <FieldOffset(0)> _
  Public type As UInteger
  <FieldOffset(4)> _
  Public mi As MOUSEINPUT
End Structure

<DllImport("user32.dll")> _
Private Function SendInput(ByVal nInputs As UIntegerByRef pInputs As INPUT, ByVal cbSize As IntegerAs UInteger
End Function

Public Function MouseEvent(ByVal dx As IntegerByVal dy As IntegerByVal mouseData As IntegerByVal dwFlags As UIntegerByVal time As UIntegerByVal dwExtraInfo As IntPtr) As UInteger
  Dim mInput As New INPUT()
  mInput.type = INPUT_MOUSE
  mInput.mi = New MOUSEINPUT()
  mInput.mi.dx = dx
  mInput.mi.dy = dy
  mInput.mi.mouseData = mouseData
  mInput.mi.dwFlags = dwFlags
  mInput.mi.time = time
  mInput.mi.dwExtraInfo = dwExtraInfo
  Return SendInput(1UI, mInput, Marshal.SizeOf(mInput))
End Function
Public Function MouseMove(ByVal dx As IntegerByVal dy As IntegerAs UInteger
  Return MouseEvent(dx * 65535 \ Screen.PrimaryScreen.Bounds.Width, dy * 65535 \ Screen.PrimaryScreen.Bounds.Height, 0, MOUSEEVENTF_ABSOLUTE Or MOUSEEVENTF_MOVE, 0UI, IntPtr.Zero)
End Function
Public Function MouseButtonDown(ByVal Button As MouseButtons) As UInteger
  Select Case (Button)
    Case MouseButtons.Left
      Return MouseEvent(000, MOUSEEVENTF_LEFTDOWN, 0UI, IntPtr.Zero)
    Case MouseButtons.Middle
      Return MouseEvent(000, MOUSEEVENTF_MIDDLEDOWN, 0UI, IntPtr.Zero)
    Case MouseButtons.Right
      Return MouseEvent(000, MOUSEEVENTF_RIGHTDOWN, 0UI, IntPtr.Zero)
    Case MouseButtons.XButton1
      Return MouseEvent(00, XBUTTON1, MOUSEEVENTF_XDOWN, 0UI, IntPtr.Zero)
    Case MouseButtons.XButton2
      Return MouseEvent(00, XBUTTON2, MOUSEEVENTF_XDOWN, 0UI, IntPtr.Zero)
    Case Else
      Return 0
  End Select
End Function
Public Function MouseButtonDown(ByVal Button As MouseButtons, ByVal dx As IntegerByVal dy As IntegerAs UInteger
  Return MouseMove(dx, dy) + MouseButtonDown(Button)
End Function
Public Function MouseButtonUp(ByVal Button As MouseButtons) As UInteger
  Select Case (Button)
    Case MouseButtons.Left
      Return MouseEvent(000, MOUSEEVENTF_LEFTUP, 0UI, IntPtr.Zero)
    Case MouseButtons.Middle
      Return MouseEvent(000, MOUSEEVENTF_MIDDLEUP, 0UI, IntPtr.Zero)
    Case MouseButtons.Right
      Return MouseEvent(000, MOUSEEVENTF_RIGHTUP, 0UI, IntPtr.Zero)
    Case MouseButtons.XButton1
      Return MouseEvent(00, XBUTTON1, MOUSEEVENTF_XUP, 0UI, IntPtr.Zero)
    Case MouseButtons.XButton2
      Return MouseEvent(00, XBUTTON2, MOUSEEVENTF_XUP, 0UI, IntPtr.Zero)
    Case Else
      Return 0
  End Select
End Function
Public Function MouseButtonUp(ByVal Button As MouseButtons, ByVal dx As IntegerByVal dy As IntegerAs UInteger
  Return MouseMove(dx, dy) + MouseButtonUp(Button)
End Function
Public Function MouseButtonClick(ByVal Button As MouseButtons) As UInteger
  Return MouseButtonDown(Button) + MouseButtonUp(Button)
End Function
Public Function MouseButtonClick(ByVal Button As MouseButtons, ByVal dx As IntegerByVal dy As IntegerAs UInteger
  Return MouseMove(dx, dy) + MouseButtonDown(Button) + MouseButtonUp(Button)
End Function
Public Function MouseWheel(ByVal Count As IntegerAs UInteger
  Return MouseEvent(00CInt(WHEEL_DELTA * Count), MOUSEEVENTF_WHEEL, 0UI, IntPtr.Zero)
End Function
Public Function MouseHWheel(ByVal Count As IntegerAs UInteger
  Return MouseEvent(00CInt(WHEEL_DELTA * Count), MOUSEEVENTF_HWHEEL, 0UI, IntPtr.Zero)
End Function



Snippets en rapport avec : Souris, Déplacer, Simuler, Simulation, Clique



Codes sources en rapport avec : Souris, Déplacer, Simuler, Simulation, Clique

{Visual Basic, VB6, VB.NET, VB 2005} MOUSE SIMULATOR
Permet de faire une simulation parfaite de sa souris !!! By JejeSoftware® (autres pseudo Grossoft...

{JAVA / J2EE} SIMULATION D'UN RÉSEAU ATM (BRASSE DES VP/VC)
Il s'agit d'une application JAVA qui "tente" (il reste du travail) de modéliser le brassage des VP/V...

{Visual Basic, VB6, VB.NET, VB 2005} ENREGISTREMENT ET SIMULATION DES CLIQUES DE SOURIS
Ce code a pour but d'enregistrer et simuler les cliques de souris. Mais il permet d'enregistrer dire...

{Visual Basic, VB6, VB.NET, VB 2005} ENREGISTREMENT ET RETRANSCRIPTION DES ACTIONS SOURIS
Voila je me lance, c'est la première source que je poste. C'est un petit programme que j'ai fait po...

{Javascript / DHTML} "DRAG" DE BLOC

Un petit exemple de drag en javascript, pour déplacer un bloc à l'aide de la souris. J'ai pas trouv...

{Javascript / DHTML} MENU CONTEXTUEL GRÂCE AU CLICK DROIT DE LA SOURIS AVEC DES MENUS SECONDAIRES VALIDÉ IE ET FIREFOX
Ce menu contextuel est déclenché par le clique droit de la souris. Le style du menu est uniquement ...

{Visual Basic, VB6, VB.NET, VB 2005} DÉPLACER LA SOURIS PAR CLAVIER
Il suffit de la déplacer avec les touches du clavier (haut, bas, gauche, droite). Code pas trop dif...

{Visual Basic, VB6, VB.NET, VB 2005} ENREGISTRER LES MOUVEMENT ET LES ACTIONS DE LA SOURIS PUIS LES REPRODUIRES
tout est dans le titre......

{Visual Basic, VB6, VB.NET, VB 2005} DÉPLACER LES CONTROLS DE SA FORM AVEC LA SOURIS
Un code pour bouger les controls de la form avec la souris. Ca peut être utile pour la réalisation ...

{C# / C#.NET} PERFORMCLICK, SIMULER LES CLIC SUR CONTRÔLES
Comme il s'agit d'un type de question qui a tendance à revenir régulièrement, voici une classe utili...