[Gambas-user] Joystick

Admin admin at allunix.ru
Fri Nov 5 17:23:39 CET 2021


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.

Dmitry.



More information about the User mailing list