ben j'ai tout retape le code sur les manettes sui se trouvait sur ce site
maintenant c'ets clair et simple!
ps: Geff c'ets the Killer de VBfrance, c'tencule y m'a vole une source!
Source / Exemple :
'// avant tout il faut:
forme1
label1 , label2
text1, text2
un bouton pour le commentaire: command1
et le timer qui analyse les touches : Timer1
- le code pour la forme1************
'Variables
Dim DirectionX As String
Dim DirectionY As String
Private Sub Command1_Click()
A = vbCrLf
MsgBox "Ben je voulais faire un Jeu utilisant la Manette" & A & "alors j'ai trouvé un code sur le Bo site de Nix , mais c'était un code trop pourri et en Anglais (Fuck les autres! Vive les Programmaurs Francais!)" & A & " Donc voila ce code Modifié, Alégé, Optimisé, Traduit par moi:" & A & "********************************" & A & "gex.rider@caramail.com" & A & "********************************" & A & A & A & "Publicité: " & A & "www.firelandteam.fr.st" & A & A & "Rq: Chez moi ca marche , j'utilise la manette deplaystation2 si avec une autre manette le code ne va pas, merci de me prevenir dans VBfrance!", vbInformation Or vbOKOnly, "***Gex Rider***"
End Sub
Private Sub Form_Load()
Dim R1&
Dim hWnd&
Static TheX As Long
Static TheY As Long
maxmin.Xbt = 0
maxmin.Ybt = 0
maxmin.Xtp = 62
maxmin.Ytp = 64
'Analyse des Fonctions de la Manette........(ben koi? moi non plus je sais pas ce que c'est !)
R1& = joySetCapture(hWnd, JOYSTICKID1, 1, 0)
R1& = joyReleaseCapture(JOYSTICKID1)
' Choppe les coordonnées de la manette et les mets dans les variables theX et TheY.
R1& = joyGetPosEx(JOYSTICKID1, myJoy)
End Sub
Public Sub LorR()
myJoy.dwSize = 64
myJoy.dwFlags = JOY_RETURNALL
Call LeftOrRight 'analyse les mouvements horizontaux
Call HautOuBas 'idem pour les verticaux
R1& = joyGetPosEx(JOYSTICKID1, myJoy)
Label1.Caption = myJoy.dwButtons 'c'te ligne est la plus simple: elle affiche la some des valeurs que la manette recoit:
' exemple si elle recoit la touche qui fait 2 et la touche qui fait 8, alors la somme affichée sera 8+2=10
' donc on peut voir que qq'un appuye sur la manette, mais il est dificile de savoir sur quelles touches quand ils y en a plusieurs
End Sub
Private Sub Timer1_Timer()
LorR 'dedans on analyse tout les bordel
Text1 = DirectionX 'puis on affiche les resultats (ici droite gauche
Text2 = DirectionY 'encore un resultat (ici haut bas)
Call setbuttons 'la on analyse presisement quelles touches sont enfoncées
Label2.Caption = "A = " + Str(buttons.A) + vbCrLf + "B = " + Str(buttons.B) + vbCrLf + "C = " + Str(buttons.C) + vbCrLf + "D = " + Str(buttons.D)
'et pour finir on ecrit les etats de chaques touches
End Sub
Sub LeftOrRight() 'cette Sub analyse si on appuye sur gauche ou droite
CURx = Mid$(myJoy.dwXpos, 1, 2)
CURy = Mid$(myJoy.dwYpos, 1, 2)
nokeyLastX = True
If CURx < maxmin.Xbt + 20 Then
DirectionX = "gauche"
nokeyLastX = False
ElseIf CURx > maxmin.Xtp - 20 Then
DirectionX = "droite"
nokeyLastX = False
Else
DirectionX = "millieu"
End If
End Sub
Sub HautOuBas() 'ici haut ou bas, ou les 2? (les 2? c'ets rare ca????)
CURx = Mid$(myJoy.dwXpos, 1, 2)
CURy = Mid$(myJoy.dwYpos, 1, 2)
nokeyLastX = True
nokeyLastX = False
nokeyLastY = True
If CURy < maxmin.Ybt + 20 Then
DirectionY = "haut"
nokeyLastY = False
ElseIf CURy > maxmin.Ytp - 20 Then
DirectionY = "bas"
Else
DirectionY = "millieu"
nokeyLastY = False
End If
End Sub
- puis le code pour le module (appelé module2 =8)*********
'liste des apis
'j'ai pas fait le menage , mais y'en a les 3/4 qui servent plus a rien
'nettoyez vous!
Declare Function joyGetPosEx Lib "winmm.dll" (ByVal uJoyID As Long, pji As JOYINFOEX) As Long
Declare Function joyReleaseCapture Lib "winmm.dll" (ByVal id As Long) As Long
Declare Function joySetCapture Lib "winmm.dll" (ByVal hWnd As Long, ByVal uID As Long, ByVal uPeriod As Long, ByVal bChanged As Long) As Long
Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long
Dim nokeyLastY As Boolean, nokeyLastX As Boolean
Public Const JOYSTICKID1 = 0
Public Const JOYSTICKID2 = 1
Public NetX, NetY, OldX, OldY, OldNetX, OldNetY
Public NetBX, NetBY, OldNetBX, OldNetBY
Public MyY, MyX, myCuRy, myCuRx
Public Const SQUARE_WID = 20
Public Const SQUARE_HGT = 20
Public Const JumpHeight = 4
Public R As Integer
Public C As Integer
Public Const JOY_POVCENTERED = -1
Public Const JOY_POVFORWARD = 0
Public Const JOY_POVRIGHT = 9000
Public Const JOY_POVLEFT = 27000
Public Const JOY_RETURNX = &H1&
Public Const JOY_RETURNY = &H2&
Public Const JOY_RETURNZ = &H4&
Public Const JOY_RETURNR = &H8&
Public Const JOY_RETURNU = &H10
Public Const JOY_RETURNV = &H20
Public Const JOY_RETURNPOV = &H40&
Public Const JOY_RETURNBUTTONS = &H80&
Public Const JOY_RETURNRAWDATA = &H100&
Public Const JOY_RETURNPOVCTS = &H200&
Public Const JOY_RETURNCENTERED = &H400&
Public Const JOY_USEDEADZONE = &H800&
Public Const JOY_RETURNALL = (JOY_RETURNX Or JOY_RETURNY Or JOY_RETURNZ Or JOY_RETURNR Or JOY_RETURNU Or JOY_RETURNV Or JOY_RETURNPOV Or JOY_RETURNBUTTONS)
Public Const JOY_CAL_READALWAYS = &H10000
Public Const JOY_CAL_READRONLY = &H2000000
Public Const JOY_CAL_READ3 = &H40000
Public Const JOY_CAL_READ4 = &H80000
Public Const JOY_CAL_READXONLY = &H100000
Public Const JOY_CAL_READYONLY = &H200000
Public Const JOY_CAL_READ5 = &H400000
Public Const JOY_CAL_READ6 = &H800000
Public Const JOY_CAL_READZONLY = &H1000000
Public Const JOY_CAL_READUONLY = &H4000000
Public Const JOY_CAL_READVONLY = &H8000000
'ca, faut pas le toucher!
Type JOYINFOEX
dwSize As Long ' taille de la structure
dwFlags As Long ' flags to indicate what to return
dwXpos As Long ' x position
dwYpos As Long ' y position
dwZpos As Long ' z position
dwRpos As Long ' rudder/4th axis position
dwUpos As Long ' 5th axis position
dwVpos As Long ' 6th axis position
dwButtons As Long ' etats des bouttons
dwButtonNumber As Long ' numero du bouton presse actuellement
dwPOV As Long ' point of view state
dwReserved1 As Long ' reserved for communication between winmm driver
dwReserved2 As Long ' reserved for future expansion
End Type
Public buttons As buttons
Public myJoy As JOYINFOEX
Public going As going
Type going
Xhu As Integer
Yhu As Integer
lastX As Long
lastY As Long
End Type
Public maxmin As maxmin
Type maxmin
Xtp As Long
Xbt As Long
Ytp As Long
Ybt As Long
Yct As Long
Xct As Long
End Type
Type buttons
A As Boolean
B As Boolean
C As Boolean
D As Boolean
End Type
Public totalY@, totalX@
Sub setbuttons() 'la sa analyse touche par touche
ButtonNo = myJoy.dwButtons
If ButtonNo = 0 Then
buttons.A = False
buttons.B = False
buttons.C = False
buttons.D = False
ElseIf ButtonNo = 1 Then
buttons.A = True
buttons.B = False
buttons.C = False
buttons.D = False
ElseIf ButtonNo = 2 Then
buttons.A = False
buttons.B = True
buttons.C = False
buttons.D = False
ElseIf ButtonNo = 3 Then
buttons.A = True
buttons.B = True
buttons.C = False
buttons.D = False
ElseIf ButtonNo = 4 Then
buttons.A = False
buttons.B = False
buttons.C = True
buttons.D = False
ElseIf ButtonNo = 5 Then
buttons.A = True
buttons.B = False
buttons.C = True
buttons.D = False
ElseIf ButtonNo = 6 Then
buttons.A = False
buttons.B = True
buttons.C = True
buttons.D = False
ElseIf ButtonNo = 7 Then
buttons.A = True
buttons.B = True
buttons.C = True
buttons.D = False
ElseIf ButtonNo = 8 Then
buttons.A = False
buttons.B = False
buttons.C = False
buttons.D = True
ElseIf ButtonNo = 9 Then
buttons.A = True
buttons.B = False
buttons.C = False
buttons.D = True
ElseIf ButtonNo = 10 Then
buttons.A = False
buttons.B = True
buttons.C = False
buttons.D = True
ElseIf ButtonNo = 11 Then
buttons.A = True
buttons.B = True
buttons.C = False
buttons.D = True
ElseIf ButtonNo = 12 Then
buttons.A = False
buttons.B = False
buttons.C = True
buttons.D = True
ElseIf ButtonNo = 13 Then
buttons.A = True
buttons.B = False
buttons.C = True
buttons.D = True
ElseIf ButtonNo = 14 Then
buttons.A = False
buttons.B = True
buttons.C = True
buttons.D = True
ElseIf ButtonNo = 15 Then
buttons.A = True
buttons.B = True
buttons.C = True
buttons.D = True
End If
End Sub
'/voila c'ets tout!
Conclusion :
c'ets simple: tu branche la manette numero 1
et tu appuye sur les boutons
c'est simple?
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.