Elle est pas trop mal mais:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Right Then
Windows.Forms.Cursor.Position = New Point(Windows.Forms.Cursor.Position.X + 10, Windows.Forms.Cursor.Position.Y)
End If
If e.KeyCode = Keys.Left Then
Windows.Forms.Cursor.Position = New Point(Windows.Forms.Cursor.Position.X - 10, Windows.Forms.Cursor.Position.Y)
End If
If e.KeyCode = Keys.Down Then
Windows.Forms.Cursor.Position = New Point(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y + 10)
End If
If e.KeyCode = Keys.Up Then
Windows.Forms.Cursor.Position = New Point(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y - 10)
End If
If e.KeyCode <> Keys.Right And e.KeyCode <> Keys.Left And e.KeyCode <> Keys.Down And e.KeyCode <> Keys.Up Or e.KeyCode = Keys.Escape Then
Me.Close()
End If
End Sub
Sinon j'ai écrit un autre code qui marche également, même si il ne gère le déplacement que dans une direction à la fois :
Const d As System.Int32 = 8
Private Sub appui_sur_touche(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Select Case e.KeyValue()
Case 37
System.Windows.Forms.Cursor.Position() = New System.Drawing.Point(System.Windows.Forms.Cursor.Position().X() - d, System.Windows.Forms.Cursor.Position().Y())
Case 38
System.Windows.Forms.Cursor.Position() = New System.Drawing.Point(System.Windows.Forms.Cursor.Position().X(), System.Windows.Forms.Cursor.Position().Y() - d)
Case 39
System.Windows.Forms.Cursor.Position() = New System.Drawing.Point(System.Windows.Forms.Cursor.Position().X() + d, System.Windows.Forms.Cursor.Position().Y())
Case 40
System.Windows.Forms.Cursor.Position() = New System.Drawing.Point(System.Windows.Forms.Cursor.Position().X(),System.Windows.Forms.Cursor.Position().Y() + d)
End Select
End Sub
Oui, bien sur ;)
N'empeche que c'est une solution simple pour par exemple mettre la souris sur le controle de ton choix...
Ou encore empecher la souris de sortir d'un bouton
...
chez moi ca se plante, en plus votre téchnique seras uniltile hors votre application parceque le KeyDown est un évenement propore à votre application c'est pourquoi jt ai deja dit faire un hook globale est la parafite solution pour faire ce genre de programme
Ma technique ne bloque pas l'utilisation "normale" de la souris ;)
Par contre, en effet, il faudrait detecter les touches du clavier autrement que par Form.OnKeyDown, mais ca se trouve ;)
Elle est pas trop mal mais:
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Right Then
Windows.Forms.Cursor.Position = New Point(Windows.Forms.Cursor.Position.X + 10, Windows.Forms.Cursor.Position.Y)
End If
If e.KeyCode = Keys.Left Then
Windows.Forms.Cursor.Position = New Point(Windows.Forms.Cursor.Position.X - 10, Windows.Forms.Cursor.Position.Y)
End If
If e.KeyCode = Keys.Down Then
Windows.Forms.Cursor.Position = New Point(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y + 10)
End If
If e.KeyCode = Keys.Up Then
Windows.Forms.Cursor.Position = New Point(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y - 10)
End If
If e.KeyCode <> Keys.Right And e.KeyCode <> Keys.Left And e.KeyCode <> Keys.Down And e.KeyCode <> Keys.Up Or e.KeyCode = Keys.Escape Then
Me.Close()
End If
End Sub
Comme ça, plus besoin de label ni de timer ...
A+
Const d As System.Int32 = 8
Private Sub appui_sur_touche(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
Select Case e.KeyValue()
Case 37
System.Windows.Forms.Cursor.Position() = New System.Drawing.Point(System.Windows.Forms.Cursor.Position().X() - d, System.Windows.Forms.Cursor.Position().Y())
Case 38
System.Windows.Forms.Cursor.Position() = New System.Drawing.Point(System.Windows.Forms.Cursor.Position().X(), System.Windows.Forms.Cursor.Position().Y() - d)
Case 39
System.Windows.Forms.Cursor.Position() = New System.Drawing.Point(System.Windows.Forms.Cursor.Position().X() + d, System.Windows.Forms.Cursor.Position().Y())
Case 40
System.Windows.Forms.Cursor.Position() = New System.Drawing.Point(System.Windows.Forms.Cursor.Position().X(),System.Windows.Forms.Cursor.Position().Y() + d)
End Select
End Sub
N'empeche que c'est une solution simple pour par exemple mettre la souris sur le controle de ton choix...
Ou encore empecher la souris de sortir d'un bouton
...
Par contre, en effet, il faudrait detecter les touches du clavier autrement que par Form.OnKeyDown, mais ca se trouve ;)
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.