[Gambas-user] Joystick
    Tobias Boege 
    tobs at taboege.de
       
    Fri Nov  5 17:31:30 CET 2021
    
    
  
On Fri, 05 Nov 2021, Admin wrote:
> 05.11.2021 23:05, Benoît Minisini пишет:
> > Le 05/11/2021 à 15:46, Admin a écrit :
> > > Greetings!
> > > 
> > > Is there still a way to read joystick events in Gambas?
> > > As I understand, it was done via gb.sdl before it was replaced with
> > > gb.sdl2, wich does not have joystick support.
> > > 
> > > Dmitry.
> > > 
> > > 
> > 
> > This has not been implemented in 'gb.sdl2'. Anyway, I don't understand
> > why reading a specific input device should be specific to a library,
> > even if joysticks are mainly used in games.
> > 
> > If anyone has more information about that...
> > 
> Totally agree. I don't need a whole SDL2 just to implement input. I wrote an
> experimental code just now to try parsing joystick myself:
> 
> ------------------------------------
> Public Sub Main()
> 
>   Shell "cat /dev/input/js0" For Read As "Joystick"
> 
> End
> -----
> Public Sub Joystick_Read()
> Dim joyEvent As String
> Dim size As Integer
> Dim events As Byte[]
> 
> size = Lof(Last)
> joyEvent = Read #Last, size
> 
> events = Byte[].FromString(joyEvent)
> 
> Print events[0], events[1], events[2], events[3], events[4], events[5],
> events[6], events[7]
> 
> End
> ------------------------------------
> 
> and it looks like it's pretty readable. I don't know what first four bytes
> mean, but last four are "pressed/released" or analog value of axis, analog
> value of second axis, number of analog stick used (buttons are always 1)
> and, finally, button number. That's totally enough. It would be nice to have
> a simple gb.joystick class that just works like keypress for joysticks, but
> this works too.
> 
Curiously, it exists in a years old merge request that I never followed
through with because it was an afternoon project and the component would
be very small and Linux-specific. But the code still exists here:
  https://gitlab.com/gambas/gambas/-/merge_requests/76
but it is written in C for incorporation into the Gambas source tree.
Yours will be easier to just dump into a project.
Best,
Tobias
-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
    
    
More information about the User
mailing list