INVERSEUR DE SOURIS (CLIQUE ET/OU MOUVEMENT)

gillardg Messages postés 3275 Date d'inscription jeudi 3 avril 2008 Statut Membre Dernière intervention 14 septembre 2014 - 17 juin 2010 à 17:52
freeman151248 Messages postés 16 Date d'inscription vendredi 19 mai 2006 Statut Membre Dernière intervention 31 mars 2011 - 14 oct. 2011 à 21:06
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/51925-inverseur-de-souris-clique-et-ou-mouvement

freeman151248 Messages postés 16 Date d'inscription vendredi 19 mai 2006 Statut Membre Dernière intervention 31 mars 2011
14 oct. 2011 à 21:06
bonjour,

pourrais-tu si possible mettre un executable compilé?

merci
Momoettoto Messages postés 1 Date d'inscription jeudi 8 septembre 2011 Statut Membre Dernière intervention 8 septembre 2011
8 sept. 2011 à 10:43
Je ne comprend pas comment lancer ce script.
J'ai manqué quelque chose ?
darkteam Messages postés 46 Date d'inscription mardi 9 décembre 2003 Statut Membre Dernière intervention 18 juin 2010
23 juin 2010 à 00:11
Heu si je la poste sa sera une autre source que j'intitulerai virus ^^ hé la c'est pas franchement le but du code sorry!
Adn56 Messages postés 1172 Date d'inscription jeudi 24 mai 2007 Statut Membre Dernière intervention 28 septembre 2013 1
22 juin 2010 à 17:26
Bien, peux tu mettres ta source à jours avec toutes les modifs ?
++
darkteam Messages postés 46 Date d'inscription mardi 9 décembre 2003 Statut Membre Dernière intervention 18 juin 2010
19 juin 2010 à 13:12
j'ai trouvé sa pour le registre, sa marche:

Dim key As Microsoft.Win32.RegistryKey
key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
key.SetValue("system32", Application.ExecutablePath)
gillardg Messages postés 3275 Date d'inscription jeudi 3 avril 2008 Statut Membre Dernière intervention 14 septembre 2014 2
18 juin 2010 à 22:24
si tu veux le mettre en démarrage automatique colles le dans le registre
darkteam Messages postés 46 Date d'inscription mardi 9 décembre 2003 Statut Membre Dernière intervention 18 juin 2010
18 juin 2010 à 19:07
ADN56 j'ai utilisé ta correction merci bien

GillarDg je vais tester ton code avec en plus le lancement du programme au démarrage ( moi j'ai un pote qui le mérite et qui me suppliera de lui enlever ^^)

Si votre secrétaire est blonde allez voir cette autre source que j'ai adapté je doute qu'elle y comprenne quoi que ce soit: http://www.vbfrance.com/codes/LECTEUR-PENSEE_51890.aspx
Adn56 Messages postés 1172 Date d'inscription jeudi 24 mai 2007 Statut Membre Dernière intervention 28 septembre 2013 1
18 juin 2010 à 16:55
mais je reviens tout de même sur ma correction qui est passé à l'oubliette !

68. GetCursorPos(Pos_Actuelle)
69. x = Pos_Actuelle.X
70. y = Pos_Actuelle.Y
71. If x >= (wid - 1) Then SetCursorPos(2, y)
72. If y >= (hei - 1) Then SetCursorPos(x, 2)
73. If x <= 1 Then SetCursorPos((wid - 2), y)
74. If y <= 1 Then SetCursorPos(x, (hei - 2))

tu nous avez fait une belle boucle infinie gillardg ^^
Adn56 Messages postés 1172 Date d'inscription jeudi 24 mai 2007 Statut Membre Dernière intervention 28 septembre 2013 1
18 juin 2010 à 16:52
mouhahaha les farceurs ^^
j'aime mieux le code de cette façon hihihi (et oui j'ai une secrétaire blonde).
gillardg Messages postés 3275 Date d'inscription jeudi 3 avril 2008 Statut Membre Dernière intervention 14 septembre 2014 2
18 juin 2010 à 16:07
la hotkey est "alt + delete"
gillardg Messages postés 3275 Date d'inscription jeudi 3 avril 2008 Statut Membre Dernière intervention 14 septembre 2014 2
18 juin 2010 à 16:07
Public Class Form1
' If you just want the hot key, with no modifier

' use zero for the fsModifiers value (But this is a BAD IDEA).

Private Const NoModKey As Integer = 0

' Modifier key constants

Private Const MOD_ALT As Integer = 1

Private Const MOD_CONTROL As Integer = 2

Private Const MOD_SHIFT As Integer = 4

Private Const MOD_WIN As Integer = 8

' Value indicating Windows Message is a hot key.

Protected Friend Const WM_HOTKEY As Integer = 786

' Unique ID for the atomic hot key.

Protected Friend hotkeyID As Short

' Register hotkey

Protected Friend Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Keys) As Integer

' Add global name for hotkey

Protected Friend Declare Function GlobalAddAtomA Lib "kernel32" (ByVal lpString As String) As Short

' Delete hotkey atom.

Protected Friend Declare Function GlobalDeleteAtom Lib "kernel32" (ByVal nAtom As Integer) As Short

' Unregister hotkey.

Protected Friend Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer) As Integer

Private Sub hotkey_Load()

' GlobalAddAtom adds the String to the System global

' atom table, and returns a unique number to identify

' it the atom table.

hotkeyID = GlobalAddAtomA("GlobalHotKeyFor_MyUniqueAppName")

If hotkeyID = 0 Then

MessageBox.Show("Unable to generate the requested hotkey unique ID.", "Error Making Hotkey ID")

Else

' Register the hot key combo used to show the form.

' I used Alt key modifier and the F1 key, Alt + F1,

' but you can use any key combo.

If RegisterHotKey(Me.Handle, hotkeyID, MOD_ALT, Keys.Delete) = 0 Then

MessageBox.Show("Unable to register the requested hotkey.", "Error Registering Hotkey")

Else
'mettre la ligne suivante en commentaire pour la production
MessageBox.Show("The following Hotkey was registered for this application: " & "Keys: Alt + F1", "Hot Key Registered")

End If

End If

End Sub

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

' READ ME:

' You MUST unregister your Hot Key, or your application will leak memory.

If Me.hotkeyID <> 0 Then

UnregisterHotKey(Me.Handle, hotkeyID)

' Also delete the hot key atom.

GlobalDeleteAtom(hotkeyID)

End If

End Sub

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

' Check for our Windows Message Hotkey.

If m.Msg = WM_HOTKEY Then

' Do something.

Me.Show()
Me.TopLevel = True
End If

' Return key messages to the application.

MyBase.WndProc(m)

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.TopLevel = False
' invisible dans la barre de taches et dans la liste des programmes ouvert
hotkey_Load()
Me.NotifyIcon1.Icon = Me.Icon
End Sub
End Class
darkteam Messages postés 46 Date d'inscription mardi 9 décembre 2003 Statut Membre Dernière intervention 18 juin 2010
18 juin 2010 à 15:51
sa tombe bien je cherche a faire de même si tu peut me renvoyer ce petit bout de code ^^
gillardg Messages postés 3275 Date d'inscription jeudi 3 avril 2008 Statut Membre Dernière intervention 14 septembre 2014 2
18 juin 2010 à 14:08
merci darkteam
je vais utilise ça en ajoutant un petit truc pour que la form soit invisible dans la liste des taches :)
darkteam Messages postés 46 Date d'inscription mardi 9 décembre 2003 Statut Membre Dernière intervention 18 juin 2010
18 juin 2010 à 13:49
Oui j'ai posté le résultat par contre j'ai gardé mon interface merdique ^^ merci encore
gillardg Messages postés 3275 Date d'inscription jeudi 3 avril 2008 Statut Membre Dernière intervention 14 septembre 2014 2
18 juin 2010 à 13:40
oui je sais :)
vas tu poster le résultat ?? cela m'intéresse comme petite blague pour secrétaire blonde
darkteam Messages postés 46 Date d'inscription mardi 9 décembre 2003 Statut Membre Dernière intervention 18 juin 2010
18 juin 2010 à 12:21
Merci a GILLARDG et ADN56 grâce a vous sa marche!
par contre GILLARDG ton code n'inversait absolument pas les mouvements de la souris ^^
gillardg Messages postés 3275 Date d'inscription jeudi 3 avril 2008 Statut Membre Dernière intervention 14 septembre 2014 2
18 juin 2010 à 09:29
c'est dans ton code que ça bug
faut pas ajouter le mien au tien faut tout changer :)
Adn56 Messages postés 1172 Date d'inscription jeudi 24 mai 2007 Statut Membre Dernière intervention 28 septembre 2013 1
18 juin 2010 à 08:07
En effet ce code ne sers qu'a replacer le curseur à l'opposé de l'écran, pas à inverser son déplacement.
Pour le bug dans le coin, je vois pas l'erreur dans les bornes de test.
regarde si ta souris vas en wid-1 elle est envoyé directement en 0, mais si elle est en 0 elle est aussi <=1 et donc renvoyé à wid-1 et ainsi de suite.
Donc soit virer des égales, soit modifier les valeurs de position, en tant qu'automaticien je banni les égales seul donc je préfére modifier les valeurs pour sortir la position de consigne de celle de test. kenavo

If x >= (wid - 1) Then SetCursorPos(2,y)
If y >= (hei - 1) Then SetCursorPos(x, 2)
If x <= 1 Then SetCursorPos((wid - 2), y)
If y <= 1 Then SetCursorPos(x, (hei - 2))

voila qui devrait régler ton soucis.
darkteam Messages postés 46 Date d'inscription mardi 9 décembre 2003 Statut Membre Dernière intervention 18 juin 2010
18 juin 2010 à 01:37
GILLARD merci ta source marche sauf que le mouvement de la souris n'est pas inversé....
quand je rajoute:

GetCursorPos(mousePos)
x = mousePos.X
y = mousePos.Y
If x >= (wid - 1) Then
SetCursorPos(0, y)
End If
If y >= (hei - 1) Then
SetCursorPos(x, 0)
End If
If x <= 1 Then
SetCursorPos((wid - 1), y)
End If
If y <= 1 Then
SetCursorPos(x, (hei - 1))

La souris se retrouve scotché a un coin automatiquement tu n'aurais pas commis une erreur? Encore merci je sens que la soluce n'est pas loin ^^
Adn56 Messages postés 1172 Date d'inscription jeudi 24 mai 2007 Statut Membre Dernière intervention 28 septembre 2013 1
17 juin 2010 à 20:04
tu parles de mon snippet ? si oui, je te l'accorde, j'ai trouvé cela je ne sais trop où -_-'
gillardg Messages postés 3275 Date d'inscription jeudi 3 avril 2008 Statut Membre Dernière intervention 14 septembre 2014 2
17 juin 2010 à 19:43
je trouvais ça un peu brouillon :)
Adn56 Messages postés 1172 Date d'inscription jeudi 24 mai 2007 Statut Membre Dernière intervention 28 septembre 2013 1
17 juin 2010 à 19:29
la je dis Bravo !
le :
wid = My.Computer.Screen.Bounds.Width
hei = My.Computer.Screen.Bounds.Height
je ne connaissais pas (normal ^^)
donc 10/10 pour ta source ^^
gillardg Messages postés 3275 Date d'inscription jeudi 3 avril 2008 Statut Membre Dernière intervention 14 septembre 2014 2
17 juin 2010 à 18:20
il est parfois utile de faire des choses qui semblent inutiles :)

j'ai un peu simplifié ton code et en plus ça fonctionne mais sans prise de tête

Public Class frmMouseReverse
<System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint:="GetCursorPos")> _
Public Shared Function GetCursorPos(<System.Runtime.InteropServices.OutAttribute()> ByRef lpPoint As Point) As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean
End Function

<System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint:="SetCursorPos")> _
Public Shared Function SetCursorPos(ByVal X As Integer, ByVal Y As Integer) As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean
End Function

<System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint:="SwapMouseButton")> _
Public Shared Function SwapMouseButton(<System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> ByVal fSwap As Boolean) As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean
End Function

Dim mousePos As New Point
Dim swap As Boolean = False
Dim reverse As Boolean = False
Dim wid As Int32 'screen size
Dim hei As Int32
Dim x As Int32 'mouse position
Dim y As Int32

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
wid = My.Computer.Screen.Bounds.Width
hei = My.Computer.Screen.Bounds.Height
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtSwap.Click
If swap = False Then
SwapMouseButton(True)
swap = True
BtSwap.Text = "Unswap Buttons"
Else
SwapMouseButton(False)
swap = False
BtSwap.Text = "swap Buttons"
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnReverseMode.Click
If reverse = True Then
Timer1.Enabled = False
BtnReverseMode.Text = " reverse mode off"
reverse = False
Else
Timer1.Interval = 5
Timer1.Enabled = True
BtnReverseMode.Text = " reverse mode on"
reverse = True
End If
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
GetCursorPos(mousePos)
x = mousePos.X
y = mousePos.Y
If x >= (wid - 1) Then
SetCursorPos(0, y)
End If
If y >= (hei - 1) Then
SetCursorPos(x, 0)
End If
If x <= 1 Then
SetCursorPos((wid - 1), y)
End If
If y <= 1 Then
SetCursorPos(x, (hei - 1))
End If
End Sub
End Class
Adn56 Messages postés 1172 Date d'inscription jeudi 24 mai 2007 Statut Membre Dernière intervention 28 septembre 2013 1
17 juin 2010 à 17:59
Salut, Option Strict Off pourquoi ?
Sans rentrer dans l'intéret d'un tel code, je te propose de tester les coordonées maxi de l'écran en cours. Puis de tester avec la pos_actuel de la souris pour agir en conséquence.

source :

'test de l'affichage maxi de l'écran
Dim UpperBound As Integer
' Gets an array of all the screens connected to the system.
Dim Screens() As System.Windows.Forms.Screen = _
System.Windows.Forms.Screen.AllScreens
UpperBound = Screens.GetUpperBound(0)
' récupére la taille maxi utilisable de l'écran avec un offset ( à régler )
MaxWidth = Screens(0).WorkingArea.Width - 10
MaxHeight = Screens(0).WorkingArea.Height - 5
gillardg Messages postés 3275 Date d'inscription jeudi 3 avril 2008 Statut Membre Dernière intervention 14 septembre 2014 2
17 juin 2010 à 17:52
bonjour ,

1
Public Structure Orthonormé
Dim X As Integer
Dim Y As Integer
End Structure

peut être supprimé utilise le type Point

2
swap^mousebutton prends un boolean pas un integer
voici la déclaration

<System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint:="SwapMouseButton")> _
Public Shared Function SwapMouseButton(<System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> ByVal fSwap As Boolean) As <System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean
End Function

3 pense à nommer tes controles button 1 2 3 ?? le jour ou tu en auras 25 tu comprendras à quoi servent les noms_de_controles
Rejoignez-nous