[SDL] The keyboard in SDL

Christer Sandberg christer.sandberg at mdh.se
Thu Feb 1 13:05:04 PST 2007


On Wednesday 31 January 2007 21:52, Christian Walther wrote:
>Christer Sandberg wrote:
>> E.g. when pressing the key with the Swedish letter 'ö' (the key with
>> a ';' on a US keyboard mapping) the content of both sym and unicode
>> is 246 (which is a correct representation of 'ö' in ISO-8859
>> encoding). The actual unicode value of 'ö' is however a two byte
>> number (in UTF-8).
>
>The unicode field contains the Unicode code point of the generated
>character (which is a number), not its UTF-8 encoded form (which is a
>sequence of bytes). The code point of 'ö' is indeed 246. In fact code
>points 0 to 255 of Unicode coincide with ISO-Latin-1, so to test whether
>SDL really produces Unicode and not Latin-1 values, you need to use
>characters that are not in Latin-1.
Thanks for your answer. I wasn't aware there existed a "code point" 
representaition (however, the SDL docs does not mention the "code point"). 
I have have spent some time trying to understand what relation there are 
between a unicode encoding like UTF-8 and "code point", but I have had little 
or no success. So I'm asking for someone to make a miracle.
From Wikipedia:
"In text processing, Unicode takes the role of providing a unique code point — 
a number, not a glyph — for each character. In other words, Unicode 
represents a character in an abstract way and leaves the visual rendering 
(size, shape, font or style) to other software, such as a web browser or word 
processor."
But as far as I know this description matches also UTF-8, or? And on 
www.unicode.org there essentially the same text:
"Characters are represented by code points that reside only in a memory 
representation, as strings in memory, or on disk. The Unicode Standard deals 
only with character codes. Glyphs represent the shapes that characters can 
have when they are rendered or displayed."
And also:
"In the Unicode character encoding model, precisely defined encoding forms 
specify how each integer (code point) for a Unicode character is to be 
expressed as a sequence of one or more code units. The Unicode Standard 
provides three distinct encoding forms for Unicode characters, using 8-bit, 
16-bit, and 32-bit units. These are correspondingly named UTF-8,..."
What I get from this is that the number representing e.g. 'ö' (246) is the 
"code point" and UTF-8 is how to organize the bits (or bytes) in that number.
But in this case the number is not even the right one (as far as I can see), 
but it is mapped to some other number (and combined with a control byte).

What I want to do is to use the Unicode code point received from SDL:s 
keyboard event using a graphical text rendering machine that expects UTF-8, 
and that the result should be the same letter as the one on the key cap of 
the users keyboard. For example just using printf to print it in a console 
that is configured for UTF-8 (I have bigger plans for the future).
Technically this must be solvable, since e.g. scanf succeeds with the trick.

Is there a function in SDL that performs a translation needed for this, or 
does anyone know about some lib providing it, or some location where I can 
find a translation table.
Thanks in advance
Christer


More information about the SDL mailing list