[SDL 1.2]SDL_SCANCODE_TO_KEYCODE return weirds values

Hello everyone :smiley:

I’m currently working on a project that use SDL 1.2 and I need to convert scan code to key code, but that doesn’t work as I expected.

For instance, if I tried to call this macro with the scan code value of B, that is 5, I would like to retrieve the key code of B, that is 98 (ASCII code).

But instead of that, I get a big number with 10 digits: 1073741829 [Shocked]

Do you know why I obtain this value ?

Thanks in advance [Wink]

How do you get the code?On Mar 12, 2014 8:56 AM, “Noxalus” wrote:

Hello everyone [image: Very Happy]

I’m currently working on a project that use SDL 1.2 and I need to convert
scan code to key code, but that doesn’t work as I expected.

For instance, if I tried to call this macro with the scan code value of B,
that is 5, I would like to retrieve the key code of B, that is 98 (ASCII
code).

But instead of that, I get a big number with 10 digits: 1073741829 [image:
Shocked]

Do you know why I obtain this value ?

Thanks in advance [image: Wink]


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

To test, I directly give an integer value to the macro:

Code:
std::cout << "Keycode: " << static_cast(SDL_SCANCODE_TO_KEYCODE(5)) << std::endl;

This simple line return me this: “Keycode: 1073741829”.

SDL 1.2 doesn’t have the macro SDL_SCANCODE_TO_KEYCODE nor any concept
of scancodes. Did you mean SDL 2.0?

In SDL 2.0, you should be using SDL_GetKeyFromScancode instead.
SDL_SCANCODE_TO_KEYCODE only works for those scancodes which have no
unicode equivalent. The actual definition of SDL_SCANCODE_TO_KEYCODE is
as follows:

#define SDLK_SCANCODE_MASK (1<<30)
#define SDL_SCANCODE_TO_KEYCODE(X) (X | SDLK_SCANCODE_MASK)

In other words, it’s a primitive macro that sets bit 30 of its argument
and otherwise leaves it untouched.On 12.03.2014 15:56, Noxalus wrote:

To test, I directly give an integer value to the macro:

Code:
std::cout << "Keycode: " << static_cast(SDL_SCANCODE_TO_KEYCODE(5)) << std::endl;


Rainer Deyke (rainerd at eldwood.com)

In fact I use Emscripten that us either SDL 1.2 either SDL 1.3.

With Emscripten, there is a distinction between key codes and scan codes like SDL 2.0.

First, I thought that the problem comes from Emscripten and I posted an issue on their Github issue system. I explain my problem better there: https://github.com/kripken/emscripten/issues/2210

With Emscripten, I can’t use the function SDL_GetKeyFromScancode, but I have access to the macro, that’s why I used it.

Do you know how do we convert scan code to key code without the macro with the SDL version used by Emscripten ?

Thanks [Wink]

Emscripten is in a “half-way state” between 1.2 and 2.0. they really shouldn’t have pulled headers from a snapshot of 1.3 to implement things. It’s on my TODO list to play around with emscriten more and get it to be fully 2.0. so, unfortunately you’ll have to prod the emscripten folks on how to handle the issue you have as emscripten SDL is just plain not compatible with SDL1.2 nor 2.0 currently.On Mar 12, 2014, at 12:20 PM, Noxalus wrote:

In fact I use Emscripten that us either SDL 1.2 either SDL 1.3.

With Emscripten, there is a distinction between key codes and scan codes like SDL 2.0.

First, I thought that the problem comes from Emscripten and I posted an issue on their Github issue system. I explain my problem better there: https://github.com/kripken/emscripten/issues/2210

With Emscripten, I can’t use the function SDL_GetKeyFromScancode, but I have access to the macro, that’s why I used it.

Do you know how do we convert scan code to key code without the macro with the SDL version used by Emscripten ?

Thanks


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I don’t really think that the problem comes from Emscripten. I checked and the scan code/key code values “send” by Emscripten are correct. If the macro that convert scan code to key code worked properly, my problem will be resolve for me.

Do you know another way to convert scan code to key code with the bastard version of SDL that Emscripten use ?

I would be interested in this, too. Currently i am using my own mapping
which of course sucks. The easiest would maybe be to implement this in
emscripten. I might give that a try in the next few days.Am 14.03.2014 09:07 schrieb “Noxalus” :

I don’t really think that the problem comes from Emscripten. I checked
and the scan code/key code values “send” by Emscripten are correct. If the
macro that convert scan code to key code worked properly, my problem will
be resolve for me.

Do you know another way to convert scan code to key code with the bastard
version of SDL that Emscripten use ?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I don’t even know how I can use my own mapping because map scan code with key code directly cannot allow me to detect layout change for example.

If I map the scan code of the key ‘a’ (4) with the key code of ‘a’ (97), this will work on a qwerty keyboard only ! :frowning:

However, that is not what that macro is for. the function SDL_GetKeyCodeFromScancode does that function. the macro is only used in the SDL_keycode.h header to build up the keysyms for entries with no unicode representation. (like F1).

So the correct solution is to create the SDL_GetKeyFromScancode method in emscripens implementation of SDL

Edward Rudd
OutOfOrder.cc
Skype: outoforder_cc
317-674-3296On Mar 14, 2014, at 4:07 AM, Noxalus wrote:

I don’t really think that the problem comes from Emscripten. I checked and the scan code/key code values “send” by Emscripten are correct. If the macro that convert scan code to key code worked properly, my problem will be resolve for me.

Do you know another way to convert scan code to key code with the bastard version of SDL that Emscripten use ?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org