IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB 6 et antérieur Discussion :

Pilotage Joystick USB


Sujet :

VB 6 et antérieur

  1. #1
    Membre éclairé
    Avatar de Asdorve
    Homme Profil pro
    Inscrit en
    Mars 2004
    Messages
    1 332
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Pyrénées Orientales (Languedoc Roussillon)

    Informations forums :
    Inscription : Mars 2004
    Messages : 1 332
    Points : 718
    Points
    718
    Par défaut Pilotage Joystick USB
    Bonjour à tous,

    J'ai en ma possession un controleur usb de ce type:
    https://fr.aliexpress.com/item/1-kit...729426394.html

    Je souhaiterais pouvoir intercepter via une interface vb une action sur un des boutons.

    Vers quelle solution dois-je m'orienter?

    Merci d'avance
    Xavier

  2. #2
    Membre confirmé Avatar de Superzest 76
    Homme Profil pro
    Automaticien
    Inscrit en
    Septembre 2018
    Messages
    144
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 26
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Automaticien
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2018
    Messages : 144
    Points : 519
    Points
    519
    Par défaut
    Salut a toi !
    Je pense qu'un espion de port USB pourrait t’être utile pour voir se que ton joystick envoie.
    Tu pourra trouver Ici un petit soft qui devrais faire l'affaire (pas testé).
    “Cookie : Anciennement petit gâteau sucré, qu’on acceptait avec plaisir. Aujourd’hui : petit fichier informatique drôlement salé, qu’il faut refuser avec véhémence.”
    N'oubliez pas le si un message vous à aider a résoudre votre problème !

  3. #3
    Membre éclairé
    Avatar de Asdorve
    Homme Profil pro
    Inscrit en
    Mars 2004
    Messages
    1 332
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Pyrénées Orientales (Languedoc Roussillon)

    Informations forums :
    Inscription : Mars 2004
    Messages : 1 332
    Points : 718
    Points
    718
    Par défaut
    Bonjour,

    Merci pour la réponse;
    J'ai trouvé un petit bout de code qui fait l'affaire:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
     
    Private Const JOY_RETURNBUTTONS As Long = &H80&
    Private Const JOY_RETURNCENTERED As Long = &H400&
    Private Const JOY_RETURNPOV As Long = &H40&
    Private Const JOY_RETURNPOVCTS As Long = &H200&
    Private Const JOY_RETURNR As Long = &H8&
    Private Const JOY_RETURNRAWDATA As Long = &H100&
    Private Const JOY_RETURNU As Long = &H10
    Private Const JOY_RETURNV As Long = &H20
    Private Const JOY_RETURNX As Long = &H1&
    Private Const JOY_RETURNY As Long = &H2&
    Private Const JOY_RETURNZ As Long = &H4&
    Private Const JOY_RETURNALL As Long = (JOY_RETURNX Or JOY_RETURNY Or JOY_RETURNZ Or JOY_RETURNR Or JOY_RETURNU Or JOY_RETURNV Or JOY_RETURNPOV Or JOY_RETURNBUTTONS)
     
    Private Type JOYINFOEX
        dwSize As Long ' size of structure
        dwFlags As Long ' flags to dicate 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 ' button states
        dwButtonNumber As Long ' current button number pressed
        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
     
    Private Declare Function joyGetPosEx Lib "winmm.dll" (ByVal uJoyID As Long, ByRef pji As JOYINFOEX) As Long
    Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
    Private Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long
     
    Dim JI As JOYINFOEX
     
    Const JNum As Long = 0
    'Set this to the number of the joystick that
    'you want to read (a value between 0 and 15).
    'The first joystick plugged in is number 0.
    'The API for reading joysticks supports up to
    '16 simultaniously plugged in joysticks.
    'Change this Const to a Dim if you want to set
    'it at runtime.
     
    Private Sub Form_Load()
    JI.dwSize = Len(JI)
    JI.dwFlags = JOY_RETURNALL
     
    'MMControl1.FileName = App.Path & "\746.mp3"
    WindowsMediaPlayer1.settings.autoStart = False
    WindowsMediaPlayer1.URL = App.Path & "\746.mp3"
    DoEvents
    End Sub
     
    Private Sub Timer1_Timer()
    Cls
    If joyGetPosEx(JNum, JI) <> 0 Then
        Print "Joystick #"; CStr(JNum); " is not plugged in, or is not working."
    Else
        With JI
            'Print "X = "; CStr(.dwXpos)
            'Print "Y = "; CStr(.dwYpos)
            'Print "Z = "; CStr(.dwZpos)
            'Print "R = "; CStr(.dwRpos)
            'Print "U = "; CStr(.dwUpos)
            'Print "V = "; CStr(.dwVpos)
            'If .dwPOV < &HFFFF& Then Print "PovAngle = "; CStr(.dwPOV / 100) Else Print "PovCentered"
            'Print "ButtonsPressedCount = "; CStr(.dwButtonNumber)
            'Print "ButtonBinaryFlags = "; CStr(.dwButtons)
            'Picture1.Cls
            'Picture1.Circle (.dwXpos / &HFFFF& * (Picture1.Width - 1), .dwYpos / &HFFFF& * (Picture1.Height - 1)), 2
     
            lblBuzzer.Caption = CStr(.dwButtons)
            PauseTime = 5    ' Set duration.
     
     
        End With
    End If
    End Sub
    Xavier

Discussions similaires

  1. Réponses: 2
    Dernier message: 22/04/2014, 09h15
  2. [Débutant] Communiquer avec un Joystick USB
    Par macErmite dans le forum MATLAB
    Réponses: 2
    Dernier message: 14/03/2013, 22h10
  3. Gèrer un joystick USB - Simulateur de vol
    Par ndech dans le forum MATLAB
    Réponses: 5
    Dernier message: 23/02/2009, 09h54
  4. Pilotage d'un interféromètre en USB
    Par vanessa31 dans le forum LabVIEW
    Réponses: 1
    Dernier message: 28/04/2008, 10h55
  5. Réponses: 2
    Dernier message: 11/09/2007, 17h03

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo