SFML community forums

Help => General => Topic started by: Dschoonmaker on July 16, 2018, 09:41:06 pm

Title: SFML Keybinds
Post by: Dschoonmaker on July 16, 2018, 09:41:06 pm
Hello, I am making a game and want to add custom keybinds (like in Zloxx II, except with gamepad support).

Currently, I have the game working with my gamepad, but I want users to be able to make it work with custom controls/gamepad.

Thanks in advance.
Title: Re: SFML Keybinds
Post by: verdog on July 17, 2018, 01:11:20 am
I think you can have the screen tell the player to press a button, save the button they press, and then set that button to be the button that activates something.
Title: Re: SFML Keybinds
Post by: fallahn on July 17, 2018, 11:08:21 am
Have a look at chapter 6 (https://github.com/SFML/SFML-Game-Development-Book) of the SFML Game Development book
Title: Re: SFML Keybinds
Post by: eXpl0it3r on July 17, 2018, 02:47:08 pm
You might also be interested in this topic: https://en.sfml-dev.org/forums/index.php?topic=23926.0
Title: Re: SFML Keybinds
Post by: Dschoonmaker on July 17, 2018, 03:29:41 pm
Wow, thanks for the quick replies, guys!  :)

verdog, I was thinking something like what you mentioned. Do you know how to save the button they pressed?

Title: Re: SFML Keybinds
Post by: Hapax on July 17, 2018, 03:50:38 pm
Do you know how to save the button they pressed?
Store the value of the keycode given in the keypressed event.
Title: Re: SFML Keybinds
Post by: Dschoonmaker on July 18, 2018, 06:07:46 pm
Hapax what about mouse or joystick events?
Title: Re: SFML Keybinds
Post by: verdog on July 18, 2018, 06:24:27 pm
Hapax what about mouse or joystick events?
For mouse you can use Mouse::Button (Documentation) (https://www.sfml-dev.org/documentation/2.5.0/structsf_1_1Event_1_1MouseButtonEvent.php).
For joystick events you can use button indexes (which are just numbers) (Documentation) (https://www.sfml-dev.org/documentation/2.5.0/structsf_1_1Event_1_1JoystickButtonEvent.php)
Title: Re: SFML Keybinds
Post by: Hapax on July 18, 2018, 09:30:05 pm
Hapax what about mouse or joystick events?
My bad. I read it as "keybinds" since the point about wanting to add controllers was within the following brackets (in the first sentence).