darksoul551
Messages postés18Date d'inscriptionlundi 7 février 2005StatutMembreDernière intervention20 août 2005
-
8 févr. 2005 à 20:14
darksoul551
Messages postés18Date d'inscriptionlundi 7 février 2005StatutMembreDernière intervention20 août 2005
-
9 févr. 2005 à 09:19
Bon, deja bonjour a tous, je tiens juste a dire que je viens de
commencer le visual basic dans le cadre de la fac, je suis donc pas
tres doué.
En fait, ce que je veux faire, c'est detecter qd l'utilisateur de
mon prog appuye sur une touche. J'ai deja parcouru le forum plein de
fois, y'en a d autres qui posent la meme question mais je comprends pas
trop...
Je balance mon code ici :
Option Explicit
Dim xc
Dim yc
Dim rc
Dim dpl1
Private Sub bref_Click()
ecran1.Print "Affichage d'un texte"
End Sub
Private Sub init_Click()
xc = 1837
yc = 1357
rc = 150
dpl1 = 150
ecran1.Cls
ecran1.Circle (xc, yc), rc
End Sub
Private Sub key_ba_Click()
If yc - dpl1 <= ecran1.Height - 3 * dpl1 Then
ecran1.Circle (xc, yc), rc, -1
yc = yc + dpl1
ecran1.Circle (xc, yc), rc, 1
End If
End Sub
Private Sub key_dr_Click()
If xc - dpl1 <= ecran1.Width - 3 * dpl1 Then
ecran1.Circle (xc, yc), rc, -1
xc = xc + dpl1
ecran1.Circle (xc, yc), rc, 1
End If
End Sub
Private Sub key_ga_Click()
If xc - dpl1 >= dpl1 Then
ecran1.Circle (xc, yc), rc, -1
xc = xc - dpl1
ecran1.Circle (xc, yc), rc, 1
End If
End Sub
Private Sub key_ht_Click()
If yc - dpl1 >= dpl1 Then
ecran1.Circle (xc, yc), rc, -1
yc = yc - dpl1
ecran1.Circle (xc, yc), rc, 1
End If
End Sub
ca donne ca :
Donc, en fait, ce que je voudrai faire, c'est juste associer une
detection de frappe clavier, par ex, si l'utilisateur appuye sur
"haut", il faudrai que le prog appelle Private Sub key_ht_Click().
cs_rene38
Messages postés1858Date d'inscriptionsamedi 29 juin 2002StatutMembreDernière intervention17 octobre 201311 8 févr. 2005 à 23:21
Bonsoir
Après avoir mis la propriété KeyPreview de la feuille ecran1 à True, modifie ton code comme ceci :
Option Explicit
Dim xc As Integer
Dim yc As Integer
Dim rc As Integer
Dim dpl1 As Integer
Private Sub Form_Load()
xc = 1837
yc = 1357
rc = 150
dpl1 = 150
ecran1.Cls
ecran1.Circle (xc, yc), rc
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyUp: key_ht
Case vbKeyLeft: key_ga
Case vbKeyDown: key_ba
Case vbKeyRight: key_dr
End Select
End Sub
Private Sub key_ba '_Click()
If yc - dpl1 <= ecran1.Height - 3 * dpl1 Then
ecran1.Circle (xc, yc), rc, -1
yc = yc + dpl1
ecran1.Circle (xc, yc), rc, 1
End If
End Sub
Private Sub key_dr '_Click()
If xc - dpl1 <= ecran1.Width - 3 * dpl1 Then
ecran1.Circle (xc, yc), rc, -1
xc = xc + dpl1
ecran1.Circle (xc, yc), rc, 1
End If
End Sub
Private Sub key_ga '_Click()
If xc - dpl1 >= dpl1 Then
ecran1.Circle (xc, yc), rc, -1
xc = xc - dpl1
ecran1.Circle (xc, yc), rc, 1
End If
End Sub
Private Sub key_ht '_Click()
If yc - dpl1 >= dpl1 Then
ecran1.Circle (xc, yc), rc, -1
yc = yc - dpl1
ecran1.Circle (xc, yc), rc, 1
End If
End Sub