New application for joysticks

Discussion in 'MDL Projects and Applications' started by stevemk14ebr, Dec 30, 2012.

  1. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    #1 stevemk14ebr, Dec 30, 2012
    Last edited: Jan 14, 2013

    Attached Files:

  2. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    #2 stevemk14ebr, Jan 5, 2013
    Last edited by a moderator: Apr 20, 2017
    (OP)
    Update V1.1 Release post any bugs or suggestions

    if you simply want to get the joystick position here is some code (the program uses a variation of this and hooks instead of using a timer like this code)
    you can delete z if you wish it is pointless for most joysticks (could be useful for joysticks that press down such as xbox controllers)
    Code:
    Imports System.Runtime.InteropServices
    Public Class Form1
        Public Declare Function joyGetPos Lib "winmm.dll" Alias "joyGetPos" (ByVal uJoyID As Integer, <MarshalAs(UnmanagedType.Struct)> ByRef pji As JOYINFO) As Integer
        <StructLayout(LayoutKind.Sequential)> _
        Public Structure JOYINFO
            Dim dwXpos As Integer                  ' x position
            Dim dwYpos As Integer                      ' y position
            Dim dwZpos As Integer
        End Structure
        Dim joypos As JOYINFO
        Dim ret As Integer
    
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            joyGetPos(0, joypos) '0 is the joystick id
            Pos.Text = joypos.dwXpos & " " & joypos.dwYpos & " " & joypos.dwZpos 'outputting coord's to textbox named pos
        End Sub
    End Class
     
  3. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    #3 stevemk14ebr, Jan 13, 2013
    Last edited: Jan 13, 2013
    (OP)
    V1.2 is out original links are updated please download the newest version the old ones are severely broken
    Changes:
    -fixed a massive bug that on left and right at a certain point it would detect both directions (Ex: press right the program calls event left AND event right) :eek:
    -more keys added (all f keys,alt,crtl,space,etc.)
    -new ui that now shows a graphical view of position
    -added a rew re-range function to show the x and y pos in a small range instead of 66000-0
    -small logical flow changes
    -Previously the check boxes were to close causing an error when unchecking in certain cases, this is fixed
     
  4. stevemk14ebr

    stevemk14ebr MDL Senior Member

    Jun 23, 2010
    267
    48
    10
    Future versions may include
    -mouse control
    -multiple key presses
    -an angle direction (ex: left and up is detected as such instead of one or the other)
    -multiple key presses per direction (ex: shift,alt, a, at the same time)
    -button control
    -z coord
    -anything else i think of
     
  5. biokemical

    biokemical MDL Novice

    Feb 20, 2013
    2
    0
    0
    Help with joystick button press counter

    Hi I was wondering if you could help me, I would like to create a button press counter for my arcade machine. Each button goes to a joystick which see's them as button 1 through to 8 for player 1 and the same for player 2 (joystick 2)
    I'm very new to VB and have tried searching for something on the net with no luck. I want the program to function as a counter eg will count the number of times joystick 1 - button 1 is pressed, button 2 ect and I would like to be able to continue on sequentially the next time the program is launched. I just thought it would be interesting to see how many presses each button is getting, some of the micro switch companies guarantee their switches for 10 million presses. Could you please help out it would be greatly appreciated!