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

Author Topic: Static Universal input class?  (Read 3177 times)

0 Members and 2 Guests are viewing this topic.

Shadowblitz16

  • Newbie
  • *
  • Posts: 13
    • View Profile
Static Universal input class?
« on: May 23, 2017, 11:27:57 pm »
does anybody know how I would go about making a universal input class that is static?
I want it to auto detect whether the input is from the keyboard or from the joystick and what joystick

I wanted the syntax to work kinda like this..
Code: [Select]
Input::SetButton(ButtonType t) // << button type is the action it is getting mapped to (a, b  up, down, left, right, start, select) returns void.
Input::GetButton(ButtonType t,  ButtonState s) // << same here but takes a button state which is (down, held and up) returns bool.

ButtonType and ButtonState would be defined in the class.

does anybody know if this is possible?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Static Universal input class?
« Reply #1 on: May 24, 2017, 04:50:17 pm »
Maybe explain a bit more in text form what you're trying to achieve. I didn't quite understand what you're after.

In case you didn't know, SFML provide sf::Keyboard::isKeyPressed(key) as well as similar functions for mouse and joysticks.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Elias Daler

  • Hero Member
  • *****
  • Posts: 599
    • View Profile
    • Blog
    • Email
Re: Static Universal input class?
« Reply #2 on: June 01, 2017, 02:26:11 pm »
Shadowblitz16 is probably asking about mapping virtual keys to multiple inputs. In this case, you should just create Input class with bunch of static std::unordered_maps which will have ButtonType as key and sf::Keyboard::Key/joystick button id as a value. Then you'll call Input::update() on each frame and check if some of the buttons in your maps were pressed. If they were, you'll store the result somewhere and will return it when calling Input::GetButton(...)
Tomb Painter, Re:creation dev (abandoned, doing other things) | edw.is | @EliasDaler

Shadowblitz16

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Static Universal input class?
« Reply #3 on: June 03, 2017, 11:44:05 pm »
can you provide some example code?
keyboards and gamepads have different function and do not support held down keys directly.
I need a way to tell if a key or button is pressed, held, or released and what direction and what axis the joypad and arrow keys are being held.

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Static Universal input class?
« Reply #4 on: June 06, 2017, 08:28:39 am »
SFML / OS X developer

 

anything