Joystick "Tap" mode with python?

Hello,

I would like to know how to use the joystick in python with something similar to the “tap” button in the logic bricks of joystick sensor.

For the keyboard, there is bge.logic.KX_INPUT_JUST_ACTIVATED which gives me the first input of the active key. But for the joystick, I’m using bge.logic.joysticks[0].activeButtons which gives me every frames where the button is pressed. Is it possible to have only the first frame of activation?

Thanks!

as far as I know, the buttons of the joystick has the same options, the sticks only have an list of five axisvalues

It doesn’t. The joystick only has a list of active buttons. http://www.blender.org/documentation/blender_python_api_2_65_3/bge.types.html#bge.types.SCA_PythonJoystick

You will have to implement a feature like “just activated” “just released” yourself by storing the previous list of active buttons and comparing the new list to that.


#function that compares list of new ie currently active and old ie previously active keys and returns 
#a list of containing both list of just activated and just released keys

def AnalyzeKeys(new, old):
    just_activated = []
    just_released = []
    for key in new:
        if not key in old:
            just_activated.append(key)
    for key in old:
        if not key in new:
            just_released.append(key)
    return [just_activated, just_released]

Let me know if you need more info on that :slight_smile:

Ok thank you!
I thought there was something in the API for that. Does it means that everything in logic brick is not always in the python API? It’s a pity but it seems not so hard to code in this case :wink:

API is not a mysterious place known only by the few. :smiley: Anyone can check what it contains and how to access it:http://www.blender.org/documentation/blender_python_api_2_69_7/bge.types.SCA_PythonJoystick.html

Theoretically python offers a subset of logic brick features, but practically you can do more with python than logic bricks and especially more complex stuff. I believe “tap” is not a feature of the joystick sensor per se, rather it’s likely a feature of the sensor class which joystick sensor inherits from.

As you start making more and more complex games python and can use API well enough to replicate anything logic could ever offer, but same is not true other way around.