Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML Keybinds  (Read 2992 times)

0 Members and 1 Guest are viewing this topic.

Dschoonmaker

  • Newbie
  • *
  • Posts: 10
    • View Profile
SFML Keybinds
« 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.

verdog

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Re: SFML Keybinds
« Reply #1 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.

fallahn

  • Hero Member
  • *****
  • Posts: 502
  • Buns.
    • View Profile
    • Trederia
Re: SFML Keybinds
« Reply #2 on: July 17, 2018, 11:08:21 am »
Have a look at chapter 6 of the SFML Game Development book

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10924
    • View Profile
    • development blog
    • Email
Re: SFML Keybinds
« Reply #3 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
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Dschoonmaker

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: SFML Keybinds
« Reply #4 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?


Hapax

  • Hero Member
  • *****
  • Posts: 3370
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: SFML Keybinds
« Reply #5 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.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Dschoonmaker

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: SFML Keybinds
« Reply #6 on: July 18, 2018, 06:07:46 pm »
Hapax what about mouse or joystick events?

verdog

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
Re: SFML Keybinds
« Reply #7 on: July 18, 2018, 06:24:27 pm »
Hapax what about mouse or joystick events?
For mouse you can use Mouse::Button (Documentation).
For joystick events you can use button indexes (which are just numbers) (Documentation)

Hapax

  • Hero Member
  • *****
  • Posts: 3370
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: SFML Keybinds
« Reply #8 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).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything