Joystick keybind

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
Desufagkun
Newbie
Posts: 11
Joined: Mon Oct 20, 2008 9:35 am
Projects: iichan erogame
Location: Russia
Contact:

Joystick keybind

#1 Post by Desufagkun » Sun Oct 13, 2013 5:28 am

Hello!
Trying to figure out how to predefine gamepad keys for some events, like pressing Menu button in gamepad opens ingame menu or pressing B key returns player one step back. By default only A key (Select/Dismiss) and directional buttons are assigned.
I can configure it from layout.classic_joystick_preferences without problems but I want to deliver game to players with already predefined gamepad keys so they do not need to enter preferences and define keys
Any help?

User avatar
nyaatrap
Crawling Chaos
Posts: 1824
Joined: Mon Feb 13, 2012 5:37 am
Location: Kimashi Tower, Japan
Contact:

Re: Joystick keybind

#2 Post by nyaatrap » Sun Oct 13, 2013 8:40 am

Coied form my game

Code: Select all

init python:
  if persistent.firstboot is None:
    _preferences.joymap['joy_dissmiss'] = "Button 0.0"
    _preferences.joymap['joy_menu'] = "Button 0.1"
    _preferences.joymap['joy_hide'] = "Button 0.2"
    _preferences.joymap['joy_rollback'] = "Button 0.3"
    _preferences.joymap['joy_skip'] = "Button 0.4"
    persistent.firstboot=True

User avatar
Desufagkun
Newbie
Posts: 11
Joined: Mon Oct 20, 2008 9:35 am
Projects: iichan erogame
Location: Russia
Contact:

Re: Joystick keybind

#3 Post by Desufagkun » Sun Oct 13, 2013 9:16 am

nyaatrap, thank you!
And another question. Is it possible to map Dpad buttons? Currently only navigation with left stick works. Tested with xbox 360 and generic DirectInput controllers.

User avatar
Desufagkun
Newbie
Posts: 11
Joined: Mon Oct 20, 2008 9:35 am
Projects: iichan erogame
Location: Russia
Contact:

Re: Joystick keybind

#4 Post by Desufagkun » Wed Nov 13, 2013 6:06 am

Well. Figured that out by myself. Now I can bind D-Pad buttons. Modified \renpy\display\joystick.py
Added new section before if ev.type == pygame.JOYBUTTONDOWN::

Code: Select all

    if ev.type == pygame.JOYHATMOTION:
        if not renpy.display.interface.focused:
            return None

        press = None

        if (ev.value[0] == -1) and (ev.value[1] == 0):
            press = "D-PAD Left"
        if (ev.value[0] == 1) and (ev.value[1] == 0):
            press = "D-PAD Right"
        if (ev.value[0] == 0) and (ev.value[1] == 1):
            press = "D-PAD Up"
        if (ev.value[0] == 0) and (ev.value[1] == -1):
            press = "D-PAD Down"
        
        if not press:
            return None

        return pygame.event.Event(renpy.display.core.JOYEVENT,
                                  press=press,
                                  release=None)
P.S. Code is not perfect because I don't know python.. But it works for me.

Post Reply

Who is online

Users browsing this forum: Google [Bot]