Joypadbuttons gleichzeitig abfragen get net mit Joygetposex

Für allgemeine Fragen zur Programmierung mit PureBasic.
3dhubiflieger
Beiträge: 123
Registriert: 27.10.2013 12:13

Joypadbuttons gleichzeitig abfragen get net mit Joygetposex

Beitrag von 3dhubiflieger »

Hallo,seh ich das richtig das es mit joygetposex keine Möglichkeit gibt die normalen Buttons gleichzeitig abzufragen ? Wenn ich Button 1 oder 2 drücke dann klappt es. Aber wenn ich beide drücke, dann ist entweder der eine oder andere oder gar kein Knopf "#True". Wie krieg ich hin das mir die Knöpfe gleichzeitig zurückgegeben werden, so wie in der Joystickbuttonroutine von Purebasic ? Denn da funktioniert es. Allerdings kann ich hier nicht alle Buttons eines 360 Gamepads ansprechen ??!

Code: Alles auswählen

Structure joy_infoex
  size.l
  flags.l
  xpos.l
  ypos.l
  zpos.l
  rpos.l
  upos.l
  vpos.l
  buttons.l
  buttonNumber.l
  pov.l
  reserved1.l
  reserved2.l
EndStructure

Global joy_status.joy_infoex
joy_status\size = SizeOf(joy_infoex)
joy_status\flags = #JOY_RETURNALL



Procedure joy_button(joystick.l, button.l)
  joyGetPosEx_(joystick, @joy_status)
  If joy_status\buttons = button
    ProcedureReturn #True
  EndIf
  ProcedureReturn #False
EndProcedure


Repeat
  Delay(200)
  If joy_button(1,1) = #True
    Debug "Button 1"
  EndIf
  
   If joy_button(1,2) = #True
    Debug "Button 2"
  EndIf
  

  ForEver
Benutzeravatar
STARGÅTE
Kommando SG1
Beiträge: 7039
Registriert: 01.11.2005 13:34
Wohnort: Glienicke
Kontaktdaten:

Re: Joypadbuttons gleichzeitig abfragen get net mit Joygetpo

Beitrag von STARGÅTE »

Der Status der Buttons wird in Bits gespeichert.
Deine Abfrage ist also doppelt falsch.
Zum einen musst je Button nummer das richtige Bit finden (1<<(Nummer-1)) und dann mit & abfragen:

Code: Alles auswählen

Procedure joy_button(joystick.l, button.l)
  joyGetPosEx_(joystick, @joy_status)
  If joy_status\buttons & (1<<(button-1)) ; Buttons sind dann von 1 bis 12
    ProcedureReturn #True
  EndIf
  ProcedureReturn #False
EndProcedure
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Aktuelles Projekt: Lizard - Skriptsprache für symbolische Berechnungen und mehr
3dhubiflieger
Beiträge: 123
Registriert: 27.10.2013 12:13

Re: Joypadbuttons gleichzeitig abfragen get net mit Joygetpo

Beitrag von 3dhubiflieger »

Ok danke für die Antwort Stargate. Ich schreib grad von der Arbeit. Werds heut abend mal testen. Wieso werden eigentlich nur die Buttons von 1 - 12 in Deinem Code abgefragt ? In der normalen Purebasic Joypadroutine geht es bis 32 ? Kannst Du mir vielleicht auch noch ne Erlärung zukommen lassen was 1<< genau bedeutet ? Ok irgendwas mit Bit finden. Aber ich weiss nicht was die Zeichen genau aussagen.
Jedenfalls schon mal danke für die Hilfe, ich melde mich heute abend nochmal.

Gruss Kevin
Benutzeravatar
STARGÅTE
Kommando SG1
Beiträge: 7039
Registriert: 01.11.2005 13:34
Wohnort: Glienicke
Kontaktdaten:

Re: Joypadbuttons gleichzeitig abfragen get net mit Joygetpo

Beitrag von STARGÅTE »

Im Button-Feld werden durchaus 32-Bits also 32Buttons angeboten, aber ich kenne keine Gamepads die mehr als 12 Buttons haben.
(1<<n) bedeutet, dass die 1 (binär ...00000001) um n Bits nach links verschoben wird also für n=4 zB: ....00010000
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Aktuelles Projekt: Lizard - Skriptsprache für symbolische Berechnungen und mehr
3dhubiflieger
Beiträge: 123
Registriert: 27.10.2013 12:13

Re: Joypadbuttons gleichzeitig abfragen get net mit Joygetpo

Beitrag von 3dhubiflieger »

mmm, supi Stargate :wink: das hat schon mal geklappt. Allerdings kapier ich das mit dem bitweisen verschieben immer noch net ganz. Muss mich da mal einarbeiten.
Hab jetzt jedenfalls das gleiche Problem mit Pov in der Routine (unten).
Woher weiss ich denn wo die bits für pov links und pov hoch liegen ? gibts da ne doku ?

Code: Alles auswählen

Structure joy_infoex
  size.l
  flags.l
  xpos.l
  ypos.l
  zpos.l
  rpos.l
  upos.l
  vpos.l
  buttons.l
  buttonNumber.l
  pov.l
  reserved1.l
  reserved2.l
EndStructure

Global joy_status.joy_infoex
joy_status\size = SizeOf(joy_infoex)
joy_status\flags = #JOY_RETURNALL



Procedure joy_button(joystick.l, button.l)
  joyGetPosEx_(joystick, @joy_status)
  
  ;das hier geht schon mal wunderbar
  If joy_status\buttons & (1<<(button-1))
    ProcedureReturn #True
  EndIf
  
  
  ;hier das gleiche Problem
  ;DPad / Cooliehat                 & (1<<(#JOY_POVLEFT-1)) ..so oder was :) ??
  If button = 13 And Joy_status\Pov = #JOY_POVLEFT ;der doppelte fehler :)
    ProcedureReturn #True  
  EndIf
  If button = 14 And Joy_status\Pov = #JOY_POVRIGHT 
    ProcedureReturn #True  
  EndIf
  If button = 15 And Joy_status\Pov = #JOY_POVFORWARD 
    ProcedureReturn #True  
  EndIf
  If button = 16 And Joy_status\Pov = #JOY_POVBACKWARD
    ProcedureReturn #True  
  EndIf
  ProcedureReturn #False
EndProcedure


Repeat
  Delay(200)
  If joy_button(1,1) = #True
    Debug "Button 1"
  EndIf
 
   If joy_button(1,2) = #True
    Debug "Button 2"
  EndIf
  
  
  ;links und vor gleichzeitig ?? ...geht net
   If joy_button(1,13) = #True
    Debug "Pov links"
  EndIf
  
    If joy_button(1,15) = #True
    Debug "Pov vor"
  EndIf

  ForEver
3dhubiflieger
Beiträge: 123
Registriert: 27.10.2013 12:13

Re: Joypadbuttons gleichzeitig abfragen get net mit Joygetpo

Beitrag von 3dhubiflieger »

So, was sagst Du Stargate ? Hab das ganze mal mit selbst ermittelten Konstanten, die Purebasic
irgendwie nicht bietet umgesetzt. Es gibt zwar Pov_left usw aber kein Pov_leftbackward oder Povleftforward. Naja, schau Dirs mal an und sag was Du davon hältst. Jedenfalls funktioniert das ganze so wie ich wollte. Kann man das so lassen ?

Gruss Hubi

Code: Alles auswählen

Structure joy_infoex
  size.l
  flags.l
  xpos.l
  ypos.l
  zpos.l
  rpos.l
  upos.l
  vpos.l
  buttons.l
  buttonNumber.l
  pov.l
  reserved1.l
  reserved2.l
EndStructure

Global joy_status.joy_infoex
joy_status\size = SizeOf(joy_infoex)
joy_status\flags = #JOY_RETURNALL

#JOY_POVLEFTFORWARD   = $7b0c
#JOY_POVRIGHTFORWARD  = $1194
#JOY_POVLEFTBACKWARD  = $57e4
#JOY_POVRIGHTBACKWARD = $34bc


Procedure joy_button(joystick.l, button.l)
  joyGetPosEx_(joystick, @joy_status)

  ;das hier geht schon mal wunderbar
  If joy_status\buttons & (1<<(button-1))
    ProcedureReturn #True
  EndIf
 
 
  ;hier das gleiche Problem
  ;DPad / Cooliehat               
  If button = 13 And (Joy_status\Pov = #JOY_POVLEFT  Or Joy_status\Pov = #JOY_POVLEFTFORWARD Or Joy_status\Pov = #JOY_POVLEFTBACKWARD)
    ProcedureReturn #True  
  EndIf
  
  If button = 14 And (Joy_status\Pov = #JOY_POVRIGHT  Or Joy_status\Pov = #JOY_POVRIGHTFORWARD Or Joy_status\Pov = #JOY_POVRIGHTBACKWARD)
    ProcedureReturn #True  
  EndIf
  
  
  If button = 15 And (Joy_status\Pov = #JOY_POVFORWARD  Or Joy_status\Pov = #JOY_POVLEFTFORWARD Or Joy_status\Pov = #JOY_POVRIGHTFORWARD)
   ProcedureReturn #True  
  EndIf
 
  If button = 16 And (Joy_status\Pov = #JOY_POVBACKWARD Or Joy_status\Pov = #JOY_POVLEFTBACKWARD Or Joy_status\Pov = #JOY_POVRIGHTBACKWARD)
   ProcedureReturn #True  
 EndIf
 
  ProcedureReturn #False
EndProcedure


Repeat
  Delay(200)
  If joy_button(1,13) = #True
    Debug "pov links"
  EndIf
 
   If joy_button(1,14) = #True
    Debug "pov rechts"
  EndIf
 
   If joy_button(1,15) = #True
    Debug "Pov vor"
  EndIf
  
    If joy_button(1,16) = #True
    Debug "Pov zurück"
  EndIf

  ForEver
Benutzeravatar
STARGÅTE
Kommando SG1
Beiträge: 7039
Registriert: 01.11.2005 13:34
Wohnort: Glienicke
Kontaktdaten:

Re: Joypadbuttons gleichzeitig abfragen get net mit Joygetpo

Beitrag von STARGÅTE »

Der POV (PointOfView) enthält auch kein Bitmuster, da ja immer nur einie einzige Richtung gedrückt werden kann, das hat ja nichts mit den Buttons zu tun. Denn du verlässt ja oben schon die Procedure u.u.

Die Dokumentation gibts auf der MS-Website: http://msdn.microsoft.com/de-de/library ... s.85).aspx

Da steht dann für den POV-Wert: "Values for this member are in the range 0 through 35,900. "
Du kannst also einfach nur 100 teilen und dann hast du den Winkel.
Der PointOfView hat ja nicht nur 4 Richtungen, sondern je nach Möglichkeit auch diagonale, dann hättest du zB 45° oder so
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Aktuelles Projekt: Lizard - Skriptsprache für symbolische Berechnungen und mehr
3dhubiflieger
Beiträge: 123
Registriert: 27.10.2013 12:13

Re: Joypadbuttons gleichzeitig abfragen get net mit Joygetpo

Beitrag von 3dhubiflieger »

Etwa so ?? Ich habe blos das Gefühl das da irgendwas net stimmt !

...Grüssle

Code: Alles auswählen

Structure joy_infoex
  size.l
  flags.l
  xpos.l
  ypos.l
  zpos.l
  rpos.l
  upos.l
  vpos.l
  buttons.l
  buttonNumber.l
  pov.l
  reserved1.l
  reserved2.l
EndStructure


Procedure joy_button(joystick.l, button.l)
  Global joy_status.joy_infoex
joy_status\size = SizeOf(joy_infoex)
joy_status\flags = #JOY_RETURNALL

  
  joyGetPosEx_(joystick, @joy_status)

  
  ;das hier geht schon mal wunderbar
  If joy_status\buttons & (1<<(button-1))
    ProcedureReturn #True
  EndIf
 ;Debug Joy_status\Pov
  Select (Joy_status\Pov / 100) ;Um den Winkel zu erhalten
     Case 0 
     If Button = 13  ;hoch 
      ProcedureReturn #True
     EndIf 
     Case 45
     If Button = 13  Or Button = 14 ;hoch rechts 
      ProcedureReturn #True
     EndIf 
     Case 90
     If Button = 14  ;rechts 
      ProcedureReturn #True
     EndIf 
     Case 135
     If Button = 14 Or Button = 15  ;rechts unten 
      ProcedureReturn #True
     EndIf 
     Case 180 
     If Button = 15  ;unten
      ProcedureReturn #True
     EndIf  
     Case 225
     If Button = 15  Or Button = 16 ;links / unten
      ProcedureReturn #True
     EndIf  
     Case 270
     If Button = 16  ;links
      ProcedureReturn #True
     EndIf  
     Case 315
     If Button = 16 Or  Button = 13 ;links oben 
      ProcedureReturn #True
     EndIf 
     
  EndSelect
  
  

 
  ProcedureReturn #False
EndProcedure


Repeat
  Delay(100)
  If joy_button(1,13)
    Debug "hoch"
  EndIf
  
  
  If joy_button(1,14)  ; rechts
   Debug "rechts"  
 EndIf  
 
 
  If joy_button(1,15)  ; rechts
   Debug "unten"  
 EndIf  
 
  If joy_button(1,16)  ; rechts
   Debug "links"  
  EndIf  
 

  ForEver

Antworten