elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Rompecabezas de Bitcoin, Medio millón USD en premios


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Game Pad plz
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Game Pad plz  (Leído 2,676 veces)
visualfree

Desconectado Desconectado

Mensajes: 201


Ver Perfil
Game Pad plz
« en: 21 Diciembre 2008, 01:04 am »

Alguien sabra como programar un game pad usb en visual basic? para controlar los botones del game pad usb ,por ejemplo si se presiona la flecha hacia arriba del gamepad haga un msgbox("arrib")  y haci con los demas botones del gamepad?


En línea

CICOLO_111234

Desconectado Desconectado

Mensajes: 200

CICOLO_111234


Ver Perfil WWW
Re: Game Pad plz
« Respuesta #1 en: 21 Diciembre 2008, 08:27 am »

puedes hacerlo con KEYUP:


Código:
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp msgbox "arriba"
If KeyCode = vbKeyDown Then msgbox "abajo"
If KeyCode = 32 Then msgbox "espacio"
end sub


En línea

BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: Game Pad plz
« Respuesta #2 en: 21 Diciembre 2008, 08:35 am »

ahora que estuve estudiando DirectX recuerdo que con DirectInput de DirectX se puede hacer tal cosa xD de igual forma con una api no recuerdo cual xP

aca te dejo el source del ejemplo de SDK del DirectX8

nesesitas 4 listbox

lstJoySticks  <-- Lista cons joysticks
lstJoyAxis    <-- se ve si se oprimio arriba abajo derecha e izquierda
lstButton   <-- indica que boton se oprimio
lstHat        <-- no recuerdo era algo de POVs

En el formulario pega este codigo.

ASI NESESITAS LA REFERENCIA A " DirectX 8 for Visual Basic Type Library " es el archivo con nombre " dx8vb.dll "
Código
  1.  
  2. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  3. '
  4. '  Copyright (C) 1999-2001 Microsoft Corporation.  All Rights Reserved.
  5. '
  6. '  File:       FrmMain.Frm
  7. '  Content:    This sample shows one way to use DirectInput with a Joystick device
  8. '
  9. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  10.  
  11. Option Explicit
  12. Implements DirectXEvent8
  13.  
  14.  
  15. Dim dx As New DirectX8
  16. Dim di As DirectInput8
  17. Dim diDev As DirectInputDevice8
  18. Dim diDevEnum As DirectInputEnumDevices8
  19. Dim EventHandle As Long
  20. Dim joyCaps As DIDEVCAPS
  21. Dim js As DIJOYSTATE
  22. Dim DiProp_Dead As DIPROPLONG
  23. Dim DiProp_Range As DIPROPRANGE
  24. Dim DiProp_Saturation As DIPROPLONG
  25. Dim AxisPresent(1 To 8) As Boolean
  26. Dim running As Boolean
  27.  
  28. Sub InitDirectInput()
  29.  
  30.    Set di = dx.DirectInputCreate()
  31.    Set diDevEnum = di.GetDIDevices(DI8DEVCLASS_GAMECTRL, DIEDFL_ATTACHEDONLY)
  32.    If diDevEnum.GetCount = 0 Then
  33.      MsgBox "No joystick attached."
  34.      Unload Me
  35.    End If
  36.  
  37.    'Add attached joysticks to the listbox
  38.    Dim i As Integer
  39.    For i = 1 To diDevEnum.GetCount
  40.        Call lstJoySticks.AddItem(diDevEnum.GetItem(i).GetInstanceName)
  41.    Next
  42.  
  43.    ' Get an event handle to associate with the device
  44.    EventHandle = dx.CreateEvent(Me)
  45.    Exit Sub
  46.  
  47. Error_Out:
  48.    MsgBox "Error initializing DirectInput."
  49.    Unload Me
  50.  
  51. End Sub
  52.  
  53.  
  54. Private Sub DirectXEvent8_DXCallback(ByVal eventid As Long)
  55.  
  56. ' This is called whenever there's a change in the joystick state.
  57. ' We check the new state and update the display.
  58.  
  59.  
  60.    Dim i As Integer
  61.    Dim ListPos As Integer
  62.    Dim S As String
  63.  
  64.    If diDev Is Nothing Then Exit Sub
  65.  
  66.    '' Get the device info
  67.    On Local Error Resume Next
  68.    diDev.GetDeviceStateJoystick js
  69.    If Err.Number = DIERR_NOTACQUIRED Or Err.Number = DIERR_INPUTLOST Then
  70.        diDev.Acquire
  71.        Exit Sub
  72.    End If
  73.  
  74.  
  75.    On Error GoTo err_out
  76.  
  77.    ' Display axis coordinates
  78.    ListPos = 0
  79.    For i = 1 To 8
  80.        If AxisPresent(i) Then
  81.           Select Case i
  82.               Case 1
  83.                   S = "X: " & js.x
  84.               Case 2
  85.                   S = "Y: " & js.y
  86.               Case 3
  87.                   S = "Z: " & js.z
  88.               Case 4
  89.                   S = "RX: " & js.rx
  90.               Case 5
  91.                   S = "RY: " & js.ry
  92.               Case 6
  93.                   S = "RZ: " & js.rz
  94.               Case 7
  95.                   S = "Slider0: " & js.slider(0)
  96.               Case 8
  97.                   S = "Slider1: " & js.slider(1)
  98.  
  99.           End Select
  100.           lstJoyAxis.List(ListPos) = S
  101.           ListPos = ListPos + 1
  102.  
  103.        End If
  104.     Next
  105.  
  106.    ' Buttons
  107.  
  108.    For i = 0 To joyCaps.lButtons - 1
  109.        Select Case js.Buttons(i)
  110.        Case 0
  111.            lstButton.List(i) = "Button " + CStr(i + 1) + ": Up"
  112.  
  113.        Case Else
  114.            lstButton.List(i) = "Button " + CStr(i + 1) + ": Down"
  115.  
  116.        End Select
  117.    Next
  118.  
  119.     ' Hats
  120.    For i = 0 To joyCaps.lPOVs - 1
  121.        lstHat.List(i) = "POV " + CStr(i + 1) + ": " + CStr(js.POV(i))
  122.    Next
  123.  
  124.    Me.Caption = "Joystick Sample: Available"
  125.  
  126.    Exit Sub
  127.  
  128. err_out:
  129.    MsgBox Err.Description & " : " & Err.Number, vbApplicationModal
  130.    End
  131.  
  132. End Sub
  133.  
  134.  
  135. Private Sub Form_Load()
  136.    running = True
  137.    InitDirectInput
  138. End Sub
  139.  
  140.  
  141. Private Sub Form_Unload(cancel As Integer)
  142.   On Local Error Resume Next
  143.   If EventHandle <> 0 Then dx.DestroyEvent EventHandle
  144.  
  145.   running = False
  146.  
  147.   'Unacquire if we are holding a device
  148.   If Not diDev Is Nothing Then
  149.      diDev.Unacquire
  150.   End If
  151.  
  152.   DoEvents
  153.   End
  154. End Sub
  155.  
  156. Private Sub lstJoySticks_Click()
  157.  
  158.  
  159.    On Local Error Resume Next
  160.  
  161.    Call CLRLISTS
  162.  
  163.  
  164.    'Unacquire the current device
  165.    'if we are holding a device
  166.    If Not diDev Is Nothing Then
  167.      diDev.Unacquire
  168.    End If
  169.  
  170.    'Create the joystick device
  171.    Set diDev = Nothing
  172.    Set diDev = di.CreateDevice(diDevEnum.GetItem(lstJoySticks.ListIndex + 1).GetGuidInstance)
  173.    diDev.SetCommonDataFormat DIFORMAT_JOYSTICK
  174.    diDev.SetCooperativeLevel Me.hWnd, DISCL_BACKGROUND Or DISCL_NONEXCLUSIVE
  175.  
  176.    ' Find out what device objects it has
  177.    diDev.GetCapabilities joyCaps
  178.    Call IdentifyAxes(diDev)
  179.  
  180.    ' Ask for notification of events
  181.    Call diDev.SetEventNotification(EventHandle)
  182.  
  183.    ' Set deadzone for X and Y axis to 10 percent of the range of travel
  184.    With DiProp_Dead
  185.        .lData = 1000
  186.        .lHow = DIPH_BYOFFSET
  187.  
  188.        .lObj = DIJOFS_X
  189.        diDev.SetProperty "DIPROP_DEADZONE", DiProp_Dead
  190.  
  191.        .lObj = DIJOFS_Y
  192.        diDev.SetProperty "DIPROP_DEADZONE", DiProp_Dead
  193.  
  194.    End With
  195.  
  196.    ' Set saturation zones for X and Y axis to 5 percent of the range
  197.    With DiProp_Saturation
  198.        .lData = 9500
  199.        .lHow = DIPH_BYOFFSET
  200.  
  201.        .lObj = DIJOFS_X
  202.         diDev.SetProperty "DIPROP_SATURATION", DiProp_Saturation
  203.  
  204.        .lObj = DIJOFS_Y
  205.         diDev.SetProperty "DIPROP_SATURATION", DiProp_Saturation
  206.  
  207.    End With
  208.  
  209.    SetPropRange
  210.  
  211.  
  212.    diDev.Acquire
  213.    Me.Caption = "Joystick Sample: Querying Properties"
  214.  
  215.    ' Get the list of current properties
  216.    ' USB joysticks wont call this callback until you play with the joystick
  217.    ' so we call the callback ourselves the first time
  218.    DirectXEvent8_DXCallback 0
  219.  
  220.    ' Poll the device so that events are sure to be signaled.
  221.    ' Usually this would be done in Sub Main or in the game rendering loop.
  222.  
  223.    While running = True
  224.        DoEvents
  225.        diDev.Poll
  226.    Wend
  227. End Sub
  228.  
  229. Sub SetPropRange()
  230.    ' NOTE Some devices do not let you set the range
  231.    On Local Error Resume Next
  232.  
  233.    ' Set range for all axes
  234.    With DiProp_Range
  235.        .lHow = DIPH_DEVICE
  236.        .lMin = 0
  237.        .lMax = 10000
  238.    End With
  239.    diDev.SetProperty "DIPROP_RANGE", DiProp_Range
  240. End Sub
  241.  
  242. Sub CLRLISTS()
  243.    lstJoyAxis.Clear
  244.    lstButton.Clear
  245.    lstHat.Clear
  246. End Sub
  247.  
  248. Sub IdentifyAxes(diDev As DirectInputDevice8)
  249.  
  250.   ' It's not enough to count axes; we need to know which in particular
  251.   ' are present.
  252.  
  253.   Dim didoEnum As DirectInputEnumDeviceObjects
  254.   Dim dido As DirectInputDeviceObjectInstance
  255.   Dim i As Integer
  256.  
  257.   For i = 1 To 8
  258.     AxisPresent(i) = False
  259.   Next
  260.  
  261.   ' Enumerate the axes
  262.   Set didoEnum = diDev.GetDeviceObjectsEnum(DIDFT_AXIS)
  263.  
  264.   ' Check data offset of each axis to learn what it is
  265.   Dim sGuid As String
  266.   For i = 1 To didoEnum.GetCount
  267.  
  268.     Set dido = didoEnum.GetItem(i)
  269.  
  270.         sGuid = dido.GetGuidType
  271.         Select Case sGuid
  272.            Case "GUID_XAxis"
  273.              AxisPresent(1) = True
  274.            Case "GUID_YAxis"
  275.              AxisPresent(2) = True
  276.            Case "GUID_ZAxis"
  277.              AxisPresent(3) = True
  278.            Case "GUID_RxAxis"
  279.              AxisPresent(4) = True
  280.            Case "GUID_RyAxis"
  281.              AxisPresent(5) = True
  282.            Case "GUID_RzAxis"
  283.              AxisPresent(6) = True
  284.            Case "GUID_Slider"
  285.                AxisPresent(8) = True
  286.                AxisPresent(7) = True
  287.         End Select
  288.  
  289.   Next
  290. End Sub
  291.  

P.D.: Se puede hacer un KeyLogger efectivo con DirectX (igual con DirectInput) xP jejeje... la desventaja es que se nesesita una dependecia ¬¬# según la Version del DirectX usado, aun que tiene arreglo usando el coco xP ¡!.

La api no la recuerdo jejeje... consulta la API-Guide.¡!  xP

Saludos
En línea

The Dark Shadow is my passion.
BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: Game Pad plz
« Respuesta #3 en: 21 Diciembre 2008, 08:38 am »

puedes hacerlo con KEYUP:


Código:
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp msgbox "arriba"
If KeyCode = vbKeyDown Then msgbox "abajo"
If KeyCode = 32 Then msgbox "espacio"
end sub


Sabes lo que es un Game Pad xP es un control como los volantes o el control de la PS3 pero para PC xP eso es una Game Pad, mas no el teclado ¬¬"...¡!


Edito--->

aqui tienes las 3 apis que nesesitas para el Joystick o GamePad que a mi parecer son lo mismo xd

Código:
joyGetDevCaps
joyGetNumDevs
joyGetPos
Mas Info en:     http://allapi.mentalis.org/apilist/j.shtml

El ejemplo con Apis de la pagina ya mensionada.

Código
  1. ' defines and structures
  2. Const JOY_BUTTON1 = &H1
  3. Const JOY_BUTTON2 = &H2
  4. Const JOY_BUTTON3 = &H4
  5. Const JOY_BUTTON4 = &H8
  6. Const JOYERR_BASE = 160
  7. Const JOYERR_NOERROR = (0)
  8. Const JOYERR_NOCANDO = (JOYERR_BASE + 6)
  9. Const JOYERR_PARMS = (JOYERR_BASE + 5)
  10. Const JOYERR_UNPLUGGED = (JOYERR_BASE + 7)
  11. Const MAXPNAMELEN = 32
  12. Const JOYSTICKID1 = 0
  13. Const JOYSTICKID2 = 1
  14.  
  15. Private Type JOYINFO
  16.   X As Long
  17.   Y As Long
  18.   Z As Long
  19.   Buttons As Long
  20. End Type
  21. Private Type JOYCAPS
  22.   wMid As Integer
  23.   wPid As Integer
  24.   szPname As String * MAXPNAMELEN
  25.   wXmin As Long
  26.   wXmax As Long
  27.   wYmin As Long
  28.   wYmax As Long
  29.   wZmin As Long
  30.   wZmax As Long
  31.   wNumButtons As Long
  32.   wPeriodMin As Long
  33.   wPeriodMax As Long
  34. End Type
  35.  
  36. Private Declare Function joyGetDevCaps Lib "winmm.dll" Alias "joyGetDevCapsA" (ByVal id As Long, lpCaps As JOYCAPS, ByVal uSize As Long) As Long
  37. Private Declare Function joyGetNumDevs Lib "winmm.dll" () As Long
  38. Private Declare Function joyGetPos Lib "winmm.dll" (ByVal uJoyID As Long, pji As JOYINFO) As Long
  39. Private Function GetJoystick(ByVal joy As Integer, JI As JOYINFO) As Boolean
  40.   If joyGetPos(joy, JI) <> JOYERR_NOERROR Then
  41.      GetJoystick = False
  42.   Else
  43.      GetJoystick = True
  44.   End If
  45. End Function
  46. ' If IsConnected is False then it returns the number of
  47. ' joysticks the driver supports. (But may not be connected)
  48. '
  49. ' If IsConnected is True the it returns the number of
  50. ' joysticks present and connected.
  51. '
  52. ' IsConnected is true by default.
  53. Private Function IsJoyPresent(Optional IsConnected As Variant) As Long
  54.   Dim ic As Boolean
  55.   Dim i As Long
  56.   Dim j As Long
  57.   Dim ret As Long
  58.   Dim JI As JOYINFO
  59.  
  60.   ic = IIf(IsMissing(IsConnected), True, CBool(IsConnected))
  61.  
  62.   i = joyGetNumDevs
  63.  
  64.   If ic Then
  65.      j = 0
  66.      Do While i > 0
  67.         i = i - 1   'Joysticks id's are 0 and 1
  68.         If joyGetPos(i, JI) = JOYERR_NOERROR Then
  69.            j = j + 1
  70.         End If
  71.      Loop
  72.  
  73.      IsJoyPresent = j
  74.   Else
  75.      IsJoyPresent = i
  76.   End If
  77.  
  78. End Function
  79. ' Fills the ji structure with the minimum x, y, and z
  80. ' coordinates. Buttons is filled with the number of
  81. ' buttons.
  82. Private Function GetJoyMin(ByVal joy As Integer, JI As JOYINFO) As Boolean
  83.   Dim jc As JOYCAPS
  84.  
  85.   If joyGetDevCaps(joy, jc, Len(jc)) <> JOYERR_NOERROR Then
  86.      GetJoyMin = False
  87.  
  88.   Else
  89.      JI.X = jc.wXmin
  90.      JI.Y = jc.wYmin
  91.      JI.Z = jc.wZmin
  92.      JI.Buttons = jc.wNumButtons
  93.  
  94.      GetJoyMin = True
  95.   End If
  96. End Function
  97. ' Fills the ji structure with the maximum x, y, and z
  98. ' coordinates. Buttons is filled with the number of
  99. ' buttons.
  100. Private Function GetJoyMax(ByVal joy As Integer, JI As JOYINFO) As Boolean
  101.   Dim jc As JOYCAPS
  102.   If joyGetDevCaps(joy, jc, Len(jc)) <> JOYERR_NOERROR Then
  103.      GetJoyMax = False
  104.   Else
  105.      JI.X = jc.wXmax
  106.      JI.Y = jc.wYmax
  107.      JI.Z = jc.wZmax
  108.      JI.Buttons = jc.wNumButtons
  109.      GetJoyMax = True
  110.   End If
  111. End Function
  112. Private Sub Form_Paint()
  113.    'KPD-Team 1999
  114.    'URL: http://www.allapi.net/
  115.    'E-Mail: KPDTeam@Allapi.net
  116.    Dim JInfo As JOYINFO
  117.    'Clear the form
  118.    Me.Cls
  119.    'Print the information to the form
  120.    Me.Print "Number of joysticks the driver supports:" + Str$(IsJoyPresent(False))
  121.    Me.Print "Number of connected joysticks:" + Str$(IsJoyPresent(True))
  122.    GetJoystick JOYSTICKID1, JInfo
  123.    Me.Print "Number of buttons:" + Str$(JInfo.Buttons)
  124.    GetJoyMax JOYSTICKID1, JInfo
  125.    Me.Print "Max X:" + Str$(JInfo.X)
  126.    Me.Print "Max Y:" + Str$(JInfo.Y)
  127.    Me.Print "Max Z:" + Str$(JInfo.Z)
  128.    GetJoyMin JOYSTICKID1, JInfo
  129.    Me.Print "Min X:" + Str$(JInfo.X)
  130.    Me.Print "Min Y:" + Str$(JInfo.Y)
  131.    Me.Print "Min Z:" + Str$(JInfo.Z)
  132. End Sub
  133.  
« Última modificación: 21 Diciembre 2008, 08:53 am por ░▒▓BlackZeroҖ▓▒░ » En línea

The Dark Shadow is my passion.
visualfree

Desconectado Desconectado

Mensajes: 201


Ver Perfil
Re: Game Pad plz
« Respuesta #4 en: 22 Diciembre 2008, 02:15 am »

gracias por la ayuda xD...
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
problema con el game en dev c++
Programación C/C++
dmnt82 9 5,158 Último mensaje 21 Marzo 2014, 09:00 am
por dmnt82
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines