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

Author Topic: sf::Event::KeyPressed equals 'keysym' or 'keycode'  (Read 2913 times)

0 Members and 1 Guest are viewing this topic.

Soshimaru

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
sf::Event::KeyPressed equals 'keysym' or 'keycode'
« on: July 07, 2015, 03:14:41 am »
Hello, I always wanted to post ideas on here but never went through with it because I often found similar ideas posted by other users already on there and in the best case scenarios they were either dismissed as unimportant or didn't "match the Multimedia Library idea" (which is a shame for such a wonderful library :( but so be it)

However, I made this account because I didn't find a request QUITE like this after about 40 minutes of research and I hope my prayers to the great and powerful Laurent will not be dismissed :P

The situation
I made a simple program that initialise a 3D camera with MMO-like controls, everything works fine.
sf::Event::MouseButtonPressed works perfectly
sf::Event::TextEntered works perfectly also
sf::Event::KeyPressed SEEMED to work perfectly until now

Then I realised TextEntered returned the unicode value of the character being entered
(Shift + a = A, obviously) which is good
KeyPressed returns an enum like "sf::Keyboard::A" which is equal to a random value like "0"
(when A is pressed, the event is pulled) which works fine in most cases

The problem
If I want to implement my own keybinding, I want to know the unicode value of the keys being pressed as opposed to some arbitraty value like "A = 0" and TextEntered works for most keys but will mess up while holding modifiers or even have unwanted effects when the user try to use "^" as a key or any other foul unexpected inputs that are differed and depends on the next key

A long story made short-ish
SDL USED to have a method to get EITHER the 'unicode' (event.key.keysym.unicode, take in account modifiers like TextEntered) or 'sym' (event.key.keysym.sym, doesn't disregard modifiers but rather consider them their own keys so Shift will return its own Unicode similar to how KeyPressed acts)

After a bit of dancing around forums I arrived to the conclusion "sf::Keyboard::A" make the code look nice but it would be much better if the program launched a KeyPressed event when ANY key is pressed with a way to get its Unicode value (Ctrl = 26, etc.)

Ex:
if (event.key.code == sf::Keyboard::W) {  } //W
if (event.key.sym == 26) {  } //Ctrl (Ctrl is already taken into account in SFML but not other characters like "^")

This would be helpful not only for custom Keybinding but also work around the limited Enum we have right now wouldn't it? Please feel free to discuss about this ask me questions or tell me how I am wrong instead of just "I don't see the point" D:

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Event::KeyPressed equals 'keysym' or 'keycode'
« Reply #1 on: July 07, 2015, 06:58:55 am »
Quote
I made this account because I didn't find a request QUITE like this after about 40 minutes of research
Really? This is probably the most discussed issue on the forum, and also the one that has the most entries on the tracker. So please make sure that you read everything about key handling issues before we potentially enter another long discussion about it again...

The most relevant thread is probably this one: http://en.sfml-dev.org/forums/index.php?topic=13692.0
« Last Edit: July 07, 2015, 07:46:00 am by Laurent »
Laurent Gomila - SFML developer

Soshimaru

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: sf::Event::KeyPressed equals 'keysym' or 'keycode'
« Reply #2 on: July 07, 2015, 07:19:17 am »
I'm very sorry for this mistake on my part, but do understand that I found ONE similar request from a while back and it was SIMILAR but not identical. Even the link you gave me is from 2013.

I even made sure mid-way through writing my post by searching terms like: "sym" "symkey" "unicode" and I've been searching on forums for help for my problem and the only reply I got said to use SDL instead. Which I tried to embed into my SFML window but SDL2 changed a few things I'm unfamiliar with.

but if ANYTHING can be salvaged from this incident which seems to be quite frequent it's that sometimes it is hard to tell if ideas are being ignored on purpose or forgotten about.
Although I half expected this to happen. SURELY such a crucial feature wouldn't go unnoticed, but seriously
the 'Improve keyboard handling #7' issue on GitHub was opened in 2011 :O What happened?

Hope you find the time to implement this soon (like at least 3.0)
I find myself drawn to SFML more and the only thing holding it back for me are trivial things like this and a few window features (but call me perfectionist because it drives me mad)
« Last Edit: July 07, 2015, 07:44:56 am by Soshimaru »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::Event::KeyPressed equals 'keysym' or 'keycode'
« Reply #3 on: July 07, 2015, 07:56:13 am »
Quote
seriously the 'Improve keyboard handling #7' issue on GitHub was opened in 2011 :O What happened?
Quote
Hope you find the time to implement this soon
Quote
trivial things like this
Long forum threads and old issues on the tracker are usually a good sign that something is not trivial. This one is probably the most complicated issue that we have to deal with, and no it's not going to be "fixed" soon. It will take a long time, most likely with multiple iterations and improvements of the API.
Laurent Gomila - SFML developer

Soshimaru

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: sf::Event::KeyPressed equals 'keysym' or 'keycode'
« Reply #4 on: July 07, 2015, 08:19:42 am »
I'll try to correctly embed a SDL context in my SFML window this time and make a work-around with the new SDL2 system

Thanks for your patience

also "this is probably the only way to make these prehistoric issues progress" - Laurent
LOL

 

anything