Difference between SDL_Scancode and SDL_Keycode - sdl

I am in a learning process of SDL library by version 2.0.
When I checked out SDL_Event handling , I got two different representations for keyboard event.
SDL_Scancode
SDL_Keycode
I could not understand the difference between them.Despite trying.
What are those differences ? and Why are those as amount two ?

According to the SDL wiki:
"The scancode identifies the location of a key press and the corresponding SDL_Keycode gives that key press meaning in the context of the current keyboard layout. "
So as mentioned in the comments by #HolyBlackCat if you are using a QWERTY keyboard they will be the same, but if using an AZERTY keyboard Z should have Z keycode and W scancode
Links to relevant parts of SDL Wiki:
SDL_Scancode
SDL_Keycode

Related

C++ getting keyboard adapter when using two keyboards, determine where the keypress come from

I would like to know how to detect the keyboard adapter on Windows when using two keyboards, that a key eg. W was pressed on first or on the second keyboard.
Can anybody help me how to do it?
I would like to use a cheap solution for macros. I would plan to bind macros for entrie second keyboard, when somebody press key W (just for example), keybaord would type a world uint8_t.

How to convert X11 KeyCode or KeySym to scan code

I need to get scan codes of keyboard buttons (or any other codes) in layout-independent way. More specific, let's say I have QEditText and catching keystrokes from it. Now I'm starting to press a single button, and when the layout is English it has keycode=X, then I'm switching layout to Russian (German, French, whatever) and keycode becomes Y - but the physical button is the same. So I need to know code of that physical button, how to do this?
I am not sure if you will be able to do this only from code itself by some qt/x11 methods, but there is a tool that helps in similar situations: xbindkeys. You can read more here:
https://unix.stackexchange.com/questions/91355/shortcut-keys-that-are-independent-to-keyboard-layout
If you can't use xbindkeys, you can still check its code and see how the author achieved this.

DirectX 11 input read methods

I'm writing an application now and i need to include inputs to this app. I'm confused now a bit. I heard about four options.
1. Basic windows messages system,
2. DirectInput8,
3. RawInput,
4. XInput.
I need to distinguish:
1. uppercase letters from lowercase letters,
2. arrows and special keys from other chars (i mean left arrow key is translated to % when usgin translate message and it's problem coz i need to dostingush them),
3. it would be good if it would be possible proceed data as messages.
Now, my question is: Which one of these four would you use to implement input? Maybe you have another good way to do this?
PS. I need to handle mouse and keyboard.
If you don't need joystick gamepad support plain window messages work for everything.
To read character data that will be displayed on screen like text being entered into an input box use WM_CHAR, WM_CHAR will return different codes for a and A.
For input keys like left/right arrows etc. you can use WM_KEYDOWN / WM_KEYUP.
Windows messages work well for mouse clicks too and for mouse position I prefer to use GetCursorPos and translate it into the client window coordinates.
For other input devices XInput is the prefered choice.

is there any function to know a key of keyboard is pressed or not?

I'm writing a console application with Qt Creator and I must know if a key is pressed (or not) and make the true decision, but how could I know?
should i write a function to do this purpose ?
Have a look at QKeyEvent and google for some tutorials like this one.
How to do it depends on the operating system. For example, when you press the P key while playing a video game on your Windows PC, the game pauses. How does the game know to pause? The game is monitoring the state of the P key in a loop. Like all keys, the P key has two states (up or down). When the state changes, the key has been pressed or released. Passive keystroke loggers work this way, except they monitor all the keys, not just one.
Use QShortcut. Refer to the Qt doc for usage

Asynchronous keyboard input on win32

I'm creating a simple 3D game on Windows 7 in C++ using the free version of the Havok physics engine. I want to use the WASD keys to move the character. The structure of the code is such that I need to capture this input asychronously; there is a function called in every frame of the scene to update the character's position (I want to try checking if a key is currently pressed instead of using some kind of listener for events). I searched around for a good solution, as I know little to nothing about win32 functions, and put this together:
if (GetAsyncKeyState(0x41) & 0x8000) posX=-1.0f; //A
if (GetAsyncKeyState(0x44) & 0x8000) posX=1.0f; //D
if (GetAsyncKeyState(0x57) & 0x8000) posX=1.0f; //W
if (GetAsyncKeyState(0x53) & 0x8000) posX=-1.0f; //S
After checking with some printf statements, the visual debugger doesn't seem to be picking up any input with this. I know of WM_KEYDOWN and WM_KEYUP, but I can't find simple explanations on how to use them, and as far as I can tell they are more event-based than asynchronous.
Is there a problem with the snippet above, or should I try another approach?
Best guess: You're checking for "A" instead of "a". Unless of course you hold down the shift key as well, just pressing the a-key won't trigger your code.
It appears that my problem wasn't GetAsyncKeyState() after all, but my use of FindWindow() and GetWindowRect(). It wasn't recognizing that the current window was the visual debugger. Fixed.