[SDL 1.3] KeyboardEvent & TextInputEvent

Hello,

I try to process the keyboard input with SDL 1.3 on Windows and Linux.

First, on Linux, when the ‘Delete’ key is pressed, a TextInputEvent with
code 127 is send. But on Windows, no TextInputEvent is send when
’Delete’ is pressed, is it normal ??

I want to know when the keys Delete, Left, Right, Home & End are
pressed. For the Delete key, the scancode is the same on Windows and
Linux, but for the others keys, the scancodes are different:
Windows: Delete = 76, Left = 92, Right = 94, Home = 95, End = 89
Linux: Delete = 76, Left = 80, Right = 79, Home = 74, End = 77

And the keysym aren’t the same too. So I don’t know how to get these
keys on Linux AND Windows…

(the keyboard used is a laptop keyboard QWERTZ (swiss-french), maybe the
problem is here?)

How can I identify these keys on both OS ???

Thank you

Yannick Bersier

And the keysym aren’t the same too. So I don’t know how to get these keys on
Linux AND Windows…

For this, you’d definitely want to use keysyms rather than keycodes,
but I have no idea why they are different?!?

In Quadra, I use SDLK_BACKSPACE, SDLK_DELETE, SDLK_LEFT, SDLK_RIGHT,
SDLK_HOME, SDLK_END, tested on Linux/X11, Mac OS X (both Quartz and
X11) and Windows (XP and Vista), both with US and French Canadian
keyboard layouts (granted, they’re both QWERTY):

http://code.google.com/p/quadra/source/browse/branches/quadra-sdl/skelton/common/inter.cpp#592

Pay no attention to the quality of the code, it was written more than
ten years ago for DOS, then DirectX, then Svgalib, then X11, and SDL
only recently! It’s a bit scarred. ;-)On Wed, Nov 12, 2008 at 4:09 PM, Yannick Bersier wrote:


http://pphaneuf.livejournal.com/

Hello,

Thank you for your reply, it’s ok, I have found the problem.

It doesn’t come from SDL but from my Acer laptop keyboard.
The keys left, right, up, down, home, pgup, pgdown, end are the
SDLK_KP_* and not the ‘normal’ key code.

That was working on Linux because VirtualBox was mapping these keys with
the ‘normal’ key and not with the keypad key.

I use this code and that works fine with Windows and Linux with my Acer
keyboard:


#define ALL_KEYS(std, kp) (e.key.keysym.sym == std || (e.key.keysym.sym
== kp && !(e.key.keysym.mod & KMOD_NUM)))

if (txt->cursorPos && ALL_KEYS(SDLK_LEFT, SDLK_KP_4))
txt->cursorPos–;
else if (txt->cursorPos < strlen(txt->text) && ALL_KEYS(SDLK_RIGHT,
SDLK_KP_6))
txt->cursorPos++;

So, I think that the second problem (Delete (127) not send in TextInput
event on Windows) is coming from the laptop keyboard too.

Yannick Bersier

Pierre Phaneuf a ?crit :> On Wed, Nov 12, 2008 at 4:09 PM, Yannick Bersier <@Yannick_Bersier> wrote:

And the keysym aren’t the same too. So I don’t know how to get these keys on
Linux AND Windows…

For this, you’d definitely want to use keysyms rather than keycodes,
but I have no idea why they are different?!?

In Quadra, I use SDLK_BACKSPACE, SDLK_DELETE, SDLK_LEFT, SDLK_RIGHT,
SDLK_HOME, SDLK_END, tested on Linux/X11, Mac OS X (both Quartz and
X11) and Windows (XP and Vista), both with US and French Canadian
keyboard layouts (granted, they’re both QWERTY):

http://code.google.com/p/quadra/source/browse/branches/quadra-sdl/skelton/common/inter.cpp#592

Pay no attention to the quality of the code, it was written more than
ten years ago for DOS, then DirectX, then Svgalib, then X11, and SDL
only recently! It’s a bit scarred. :wink: