UNICODE manual page and missing translations

I had the joy of changing my application to use UNICODE translations today,
giving users the ability to get symbols using the shift keys and, even
better, actually lets me use my correct keymap instead of just getting
QWERTY.

However, I noticed a few minor problems.

  • The manual page for SDL_EnableUNICODE says…
    “to enable UNICODE… (enable=0)”
    … which is clearly incorrect.

  • The manual page doesn’t bother to mention that -1 can be passed to
    get the current state without changing anything - I had to look at the
    header to discover this, which isn’t something I’d normally do. It
    also neglects to mention how to turn translation back off.

  • It’s entertaining that SDL_GetKeyName() receives an SDLKey and has a
    table of translations that include symbols, but the only way to get
    most symbols (properly) is through UNICODE - but the ‘unicode’ field
    is a Uint16, not an SDLKey.

  • Given the above, the keyname[] table is missing some entries. Most
    noticeably ‘%’ has been omitted, but worse so have all upper case
    letters. This essentially means that SDL_GetKeyName() can’t be used
    with UNICODE, although I guess no-one does anyway.

It’d be nice to not have to both use the ‘unicode’ and ‘keysym’ fields
when a call to SDL_GetKeyName() could do the job.

Any thoughts?

Ta.

  • Deth -
  • The manual page for SDL_EnableUNICODE says…
    “to enable UNICODE… (enable=0)”
    … which is clearly incorrect.

thanks, I’ll fix that

  • The manual page doesn’t bother to mention that -1 can be passed to
    get the current state without changing anything - I had to look at the
    header to discover this, which isn’t something I’d normally do. It
    also neglects to mention how to turn translation back off.

and that

  • It’s entertaining that SDL_GetKeyName() receives an SDLKey and has a
    table of translations that include symbols, but the only way to get
    most symbols (properly) is through UNICODE - but the ‘unicode’ field
    is a Uint16, not an SDLKey.

You are confusing keyboard symbols (SDLK_*) and Unicode character codes.
An SDLKey is an abstract entity representing a key on your keyboard.
SDL_GetKeyName() translates an SDLKey (which you get in key up/down events)
to a printable string describing that key, not a character

The intended use for SDL_GetKeyName() is for the “keyboard setup” section
of your game, where you want to show the key bound to each weapon.
The Unicode translation is for text entry, where you are interested in
character codes

“Mattias Engdegard” wrote:

thanks, I’ll fix that
and that

Thanks very much.

You are confusing keyboard symbols (SDLK_*) and Unicode character codes.
An SDLKey is an abstract entity representing a key on your keyboard.
SDL_GetKeyName() translates an SDLKey (which you get in key up/down events)
to a printable string describing that key, not a character

That was the answer I expected. I’m not exactly confusing them, but you’re
right that it would be hard to write a version of SDL_GetKeyName() that
coped with both keysyms and UNICODE character codes.

My situation is a little unusual, since I’m using UNICODE to ensure that I
get the ‘correct’ translation according to the current Windows keyboard
language set-up.

I use Dvorak and if I ask SDL to just give me keysyms I get QWERTY, but the
UNICODE translation works nicely. This is a problem under Windows '95 and
’98 only - NT (and probably 2000) and, of course, X all get it right.

Under '95/'98 if you choose Dvorak and call up a DOS window you should get
QWERTY - because the keysyms are being used directly.

The intended use for SDL_GetKeyName() is for the “keyboard setup” section
of your game, where you want to show the key bound to each weapon.
The Unicode translation is for text entry, where you are interested in
character codes

Right, I knew that. I even looked at the code for Maelstrom and saw that
it turns UNICODE on and then back off when reading player names. The
problem I’d get there is that I’d get one keymap when playing the game
and a totally unrelated one for entering my name. This tends to be a
problem with most games.

The bit I wrote about SDL_GetKeyName() is a consequence of my using it to
get names like “return”, etc., to check special keys - but I’ve noticed
since I could have just used SDLK_RETURN instead… at the moment I’m
checking for a UNICODE translation then falling back on SDL_GetKeyName().

But, to get back on topic :), what’s the deal with the list of symbols
in keynames[] in SDL_keyboard.c? You can’t get keysyms that represent
them, and even if you could where’s the percent symbol?

Ta.

  • Deth -

Lee Haywood wrote:

But, to get back on topic :), what’s the deal with the list of symbols
in keynames[] in SDL_keyboard.c? You can’t get keysyms that represent
them, and even if you could where’s the percent symbol?

The keysyms are for keys not characters. Keysyms exist for each
type of key on a keyboard, not each type of character. That is why
they are all lower-case, because upper and lower case are on the same
key. The reason that there is no keysym for the percent symbol, is
because no keyboard has a percent key. You may be able to create a
percent character, but it doesn’t have its own key. I hope that was
enough astrics for you …

-- David Snopek

/-- libksd –
| The C++ Cross-Platform Game Framework
| Only want to write it once??
| http://libksd.sourceforge.net
------------

Lee Haywood wrote:

But, to get back on topic :), what’s the deal with the list of symbols
in keynames[] in SDL_keyboard.c? You can’t get keysyms that represent
them, and even if you could where’s the percent symbol?

The keysyms are for keys not characters. Keysyms exist for each
type of key on a keyboard, not each type of character. That is why
they are all lower-case, because upper and lower case are on the same
key. The reason that there is no keysym for the percent symbol, is
because no keyboard has a percent key. You may be able to create a
percent character, but it doesn’t have its own key. I hope that was
enough astrics for you …

hrm - just to break in - any suggestions on how to deal with "special"
keys? One of my keyboards has “FN, Power, Sleep, Wake” as extra keys
(plus a whole bunch of Chinese codes - it’s a standard Chinese keyboard :slight_smile:
and another has: (Microsoft Natural Pro USB)
Back, Forward, Stop, Refresh, Favorites, Web/Home, Mail, Mute,
Volume +/-, Play/Pause, Stop, Prev Track, Next Track, Media,
“My Computer”, Calculator, and Sleep. And of course the
all-present (on current north american + chinese kbds anyways)
“window-thingy key”, and “list key”

I realise I can’t go and ask these codes to be added (outside of the
"window-key" and “list key” most of these codes aren’t on many keyboards -
well except for the “fn” key on laptops but that tends to be interpreted
by hardware), what I’d like to see is how these -should- be handled.

It’d make a good FAQ question:

Q: How do I support unrecognised key on my keyboard?

support nonstandard keys. But if you wish to this is how:

[code]

though to add to this hrm this really crosses into keyboardmap territory,
which AFAIK is covered by things like X and the like and as I don’t use X
unless I have to I don’t know… (and windows if it has keyboard mapping
doesn’t bother to tell anyone - my chinese keyboard wasn’t recognised as
anything other than an ordinary PS/2 keyboard and there doesn’t seem to
be a way to enable chinese input…)

PS: I have no idea how this -should- be handled. Suppose I could figure
it out… hrm…

PPS: checkkeys doesn’t return anything for these codes - and they get spit
out in syslog as “unrecognised scancode e0 25” and “… e0 1e” (eg volume
-/+)

Och this is pretty long but I hope someone figures out what I’m looking
for :slight_smile:

G’day, eh? :slight_smile:
- TeunisOn Mon, 11 Jun 2001, David Snopek wrote:
A: -don’t-, unless for some particular reason you need your application to

hrm - just to break in - any suggestions on how to deal with "special"
keys? One of my keyboards has “FN, Power, Sleep, Wake” as extra keys

if they are common (like power), add keysyms for them. As it happens,
SDLK_POWER already exists

Back, Forward, Stop, Refresh, Favorites, Web/Home, Mail, Mute,
Volume +/-, Play/Pause, Stop, Prev Track, Next Track, Media,
“My Computer”, Calculator, and Sleep.

that’s baroque. Keys like Volume or Stop aren’t uncommon but I’m
reluctant to add keysyms for the sillier of them - probably just give
them a number and be done with it

Right, I knew that. I even looked at the code for Maelstrom and saw that
it turns UNICODE on and then back off when reading player names. The
problem I’d get there is that I’d get one keymap when playing the game
and a totally unrelated one for entering my name. This tends to be a
problem with most games.

The keysym is supposed to correspond to the symbol printed on the physical
key on the keyboard (SDL has borrowed this interpretation from X11). If you
have a QWERTY keyboard, SDLK_Q should correspond to a key marked “Q” in the
upper left corner. If you have remapped the “Q” key to produce something
Dvorakesque instead, then the keysym should still be SDLK_Q (unless you
have physically moved or repainted your keycaps), but will produce a
different Unicode value. So this is exactly how it is Supposed To Work,
and if you find it confusing with your setup, it’s because you have
started the confusion in the first place by remapping the keys.

On a real Dvorak keyboard, there should be no such problem.

But, to get back on topic :), what’s the deal with the list of symbols
in keynames[] in SDL_keyboard.c? You can’t get keysyms that represent
them, and even if you could where’s the percent symbol?

Where’s the percent key on your keyboard? I don’t have one (I have to use
shift-5)

But, to get back on topic :), what’s the deal with the list of symbols
in keynames[] in SDL_keyboard.c? You can’t get keysyms that represent
them, and even if you could where’s the percent symbol?

Where’s the percent key on your keyboard? I don’t have one (I have to use
shift-5)

Which was precisely my point, if you re-read my question. And no, I don’t
need a lecture on the difference between keysyms and characters.

Fair enough, the keypad normally has /, *, - and +. But the keynames[]
array I was referring to, used by SDL_GetKeyName() also contains symbols
such as !, ", $, (, ), etc. Where are these keys on YOUR keyboard?

My specific point was that if these are in there for ‘unusual’ keyboards,
then where’s percent? Most of the other ‘shifted’ symbols are in there.

Ta.

  • Deth -

My specific point was that if these are in there for ‘unusual’ keyboards,
then where’s percent? Most of the other ‘shifted’ symbols are in there.

most probably because of omission, but since you have no doubt observed
that keysyms 0-127 mostly happen to agree with the corresponding ascii
values (for simplicity in SDL’s internal decoder rather than for user
convenience) it’s not a big deal - the keysym is already there, just it
had no name :slight_smile:

patch follows (Sam, apply)

Index: SDL_keysym.h===================================================================
RCS file: /cvs/SDL12/include/SDL_keysym.h,v
retrieving revision 1.2
diff -u -r1.2 SDL_keysym.h
— SDL_keysym.h 2001/04/26 16:50:17 1.2
+++ SDL_keysym.h 2001/06/13 08:11:55
@@ -49,6 +49,7 @@
SDLK_QUOTEDBL = 34,
SDLK_HASH = 35,
SDLK_DOLLAR = 36,

  • SDLK_PERCENT = 37,
    SDLK_AMPERSAND = 38,
    SDLK_QUOTE = 39,
    SDLK_LEFTPAREN = 40,

Fair enough, the keypad normally has /, *, - and +.

They are called SDLK_KP_DIVIDE, SDLK_KP_MULTIPLY etc, not SDLK_SLASH or
SDLK_ASTERISK

SDL is not quite like X11 in that there’s only one SDL keysym for each
key (X11 keysyms account for all the symbols printed on the keys),
but this is usually what you want for game purposes — for real game
programmers the keyboard is just an oversized gamepad with a lot of buttons :slight_smile:

sorry if this was confusing you

My specific point was that if these are in there for ‘unusual’ keyboards,
then where’s percent? Most of the other ‘shifted’ symbols are in there.

most probably because of omission, but since you have no doubt observed
that keysyms 0-127 mostly happen to agree with the corresponding ascii
values (for simplicity in SDL’s internal decoder rather than for user
convenience) it’s not a big deal - the keysym is already there, just it
had no name :slight_smile:

This is actually because I don’t know of a keyboard that has a percent key.
If you find one, let me know.

The other keysyms are there because they are real keys on the French keyboard,
which uses shift to get the numbers, rather than the other way around.

See ya,
-Sam Lantinga, Lead Programmer, Loki Software, Inc.

Pas s?rieux?!? (you’re not serious, are you?)

I have yet to see a [french] keyboard that behaves this way, you’re
pulling our leg, right???–

Olivier A. Dagenais - Software Architect and Developer

“Sam Lantinga” wrote in message
news:E15ADEN-00005H-00 at twomix.devolution.com

My specific point was that if these are in there for 'unusual’
keyboards,

then where’s percent? Most of the other ‘shifted’ symbols are in
there.

most probably because of omission, but since you have no doubt
observed

that keysyms 0-127 mostly happen to agree with the corresponding
ascii

values (for simplicity in SDL’s internal decoder rather than for
user

convenience) it’s not a big deal - the keysym is already there,
just it

had no name :slight_smile:

This is actually because I don’t know of a keyboard that has a
percent key.
If you find one, let me know.

The other keysyms are there because they are real keys on the French
keyboard,
which uses shift to get the numbers, rather than the other way
around.

See ya,
-Sam Lantinga, Lead Programmer, Loki Software, Inc.

You don’t have alternate layouts or something? (Some other languages do. Some
even have special layouts for programmers! heh)

Either way, it sounds like a great idea! :slight_smile: I rarely use the alphanumeric
block for entering more than single digit numbers, so I might as well change
my layout (modified Dvorak for swedish, called “Svorak”) to work that way…

off to edit the map files

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Thursday 14 June 2001 01:47, Olivier Dagenais wrote:

Pas s?rieux?!? (you’re not serious, are you?)

I have yet to see a [french] keyboard that behaves this way, you’re
pulling our leg, right???

Pas s?rieux?!? (you’re not serious, are you?)

I have yet to see a [french] keyboard that behaves this way, you’re
pulling our leg, right???

You don’t have alternate layouts or something? (Some other languages do. Some
even have special layouts for programmers! heh)

Confirmation from searching through “locales” section - Polish I believe +
other languages.

I’m still wondering how to pickup the ‘special’ keys on the newer
’internet’ (and other fancy) USB keyboards. And considering how to
approach IM handling g. (too many languages :slight_smile:

G’day, eh? :slight_smile:
- Teunis

PS: though I -would- like ‘volume +/-/mute’ to work g…On Thu, 14 Jun 2001, David Olofson wrote:

On Thursday 14 June 2001 01:47, Olivier Dagenais wrote: