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

Author Topic: getPressedKey event  (Read 3021 times)

0 Members and 1 Guest are viewing this topic.

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
getPressedKey event
« on: January 23, 2013, 04:03:59 pm »
Not exactly as an event, but could qualify as one.

This feature would be used as a simple way to change the game's controls, when this event is run it polls if any key was touched and it returns the first key touched. Due to it's nature it's not logical (at least to me) for this kind of function to be inside the event loop. It could be as a way to poll for when was a key pressed through real-time keyboard input (without repetition of course), so you can easily get the code of an unknown key and use it for whatever programming you want.

sf::Keyboard::Key NewControl = sf::Keyboard::getPressedKey();
///Returns an invalid key code when no key was pressed.
///If multiple keys were pressed it returns the first one only.
///It could also have certain delay so that it keeps returning the recently pressed key for a short time.
 

This function/feature makes sense in an options menu where you want the player to easily change the input needed for the game. I suggested it as a function, but I don't know if it is really something so convenient that you can easily poll it with just that. Give your opinions towards this.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: getPressedKey event
« Reply #1 on: January 23, 2013, 04:39:06 pm »
Due to it's nature it's not logical (at least to me) for this kind of function to be inside the event loop.
Why not? You then react to the event as soon as it happens, not sometimes in the future. Also, getPressedKey() could easily miss keys if there are multiple key events in a frame, and only the last one is returned.

This function/feature makes sense in an options menu where you want the player to easily change the input needed for the game. I suggested it as a function, but I don't know if it is really something so convenient that you can easily poll it with just that. Give your opinions towards this.
I developed an action system in Thor. It unifies the handling of one-time events and realtime input, and allows boolean combinations of multiple actions (e.g. fire action if shift and X is pressed). You could take a look at it ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: getPressedKey event
« Reply #2 on: January 23, 2013, 07:10:46 pm »
This function would be implemented with events. So it would do nothing that you can't already do yourself with the current API.
Laurent Gomila - SFML developer

masskiller

  • Sr. Member
  • ****
  • Posts: 284
  • Pointers to Functions rock!
    • MSN Messenger - kyogre_jb@hotmail.com
    • View Profile
    • Email
Re: getPressedKey event
« Reply #3 on: January 23, 2013, 08:57:39 pm »
Quote
I developed an action system in Thor. It unifies the handling of one-time events and realtime input, and allows boolean combinations of multiple actions (e.g. fire action if shift and X is pressed). You could take a look at it

I have only used the particle system so far, so I'll check it.

Quote
This function would be implemented with events. So it would do nothing that you can't already do yourself with the current API.

My bad, I thought it was currently not possible to achieve, it appears I didn't think enough.
Programmer, Artist, Composer and Storyline/Script Writer of "Origin of Magic". If all goes well this could turn into a commercial project!

Finally back into the programming world!

 

anything