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

Author Topic: SFML 2 Suggestion: QWERTY equivalents  (Read 3294 times)

0 Members and 2 Guests are viewing this topic.

Chèvre

  • Newbie
  • *
  • Posts: 20
    • View Profile
SFML 2 Suggestion: QWERTY equivalents
« on: July 13, 2011, 12:53:15 pm »
I would like to define default keyboard controls for my game as such: Z, X, and C. Which is nice because all three keys are adjacent.

However, on AZERTY layouts this should be W, X, C, and with QWERTZ this should be Y, X, C. SFML 2 currently handles key codes according to the active keyboard layout, which is nice because you can tell the user that the 'W' key is indeed the 'W' key on an azerty keyboard, and not 'Z', for example.

The drawback to this is that it's pretty hard to define keyboard layout-agnostic default control settings. Since both AZERTY and QWERTZ are in widespread use in Europe, this is quite an issue.  It would be great if SFML provided a way to get key codes according to their position on the keyboard (perhaps in addition to getting which letter it maps to in the local layout).

So far, I have made a quick Python2 program that gives you the "local equivalent" of a QWERTY key, but it only works on Windows. I have yet to find out how to do this in Cocoa and X11. If anyone is interested, it's there (the API calls might be interesting): http://pastebin.com/UWtWmZ58

JAssange

  • Full Member
  • ***
  • Posts: 104
    • View Profile
SFML 2 Suggestion: QWERTY equivalents
« Reply #1 on: July 13, 2011, 01:22:30 pm »
The easiest way I can think of would just be to have an array where the value at the index of the qwerty key they pressed is the azerty key they pressed. And don't forget about us dvorak users!

Chèvre

  • Newbie
  • *
  • Posts: 20
    • View Profile
SFML 2 Suggestion: QWERTY equivalents
« Reply #2 on: July 13, 2011, 01:30:42 pm »
Quote from: "JAssange"
The easiest way I can think of would just be to have an array where the value at the index of the qwerty key they pressed is the azerty key they pressed. And don't forget about us dvorak users!


Well, the program I wrote should work with any keyboard layout that uses latin characters, so dvorak should be fine ;)

The problem with having such an array is that you would have to ask the user "which keyboard layout are you using?", which does not feel very professional. (Or you'd have to find out from digging around in the windows registry. Which may be a nightmare considering Apple keyboards for example have their own Windows layouts!)

Also, I cited AZERTY and QWERTZ as examples because they are widespread, but you would also have to create an array for 'exotic' keyboard layouts... For example, the French equivalent of dvorak, "bépo" is completely different from anything out there. If each country has its own optimized keyboard layout, making an array for every one of them would be pretty difficult.

It would be elegantly solved if SFML itself provided a way to use "physical" scancodes.

Plus, it would solve the problem that some AZERTY users face with unusable keys in SFML such as é, à, !, etc., well, pretty much any symbol key. (And I believe QWERTZ users can't use ü either, swedish users can't use å, and so on.)

EDIT: I meant they can't use these keys with IsKeyPressed (I know you can use something to get unicode text that just got typed in, but this is not meant for 'in-game' use)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML 2 Suggestion: QWERTY equivalents
« Reply #3 on: July 13, 2011, 06:37:47 pm »
Keyboard handling suffers from many bugs and limitations, so it will be rewritten one day.
Laurent Gomila - SFML developer