The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
NumLock state
bibendovsky


Joined: 06 Jun 2014
Posts: 2
Hello.

I'm trying to handle keypad keys depending on state of NumLock.
For example, if NumLock is ON and key KP_7 was pressed I call one function,
otherwise, if NumLock is OFF and key KP_7 was pressed I call another function.

Function SDL_GetModState returns zero.
Function SDL_GetKeyState returns for SDL_SCANCODE_NUMLOCKCLEAR also zero.

Is this a bug or there is a proper way to check the NumLock state?
Any advice would be much appreciated.
Re: NumLock state
AlexRou


Joined: 31 Jan 2014
Posts: 57
GetModState actually is working, its just that on startup the mod state is always off so when you press numlock while its on before starting the application the state gets reversed. You can either use platform specific methods to get the key state or use platform specific methods to toggle the LED so its off on start.

(SDL_GetModState() & KMOD_NUM) == (KMOD_NUM)

bibendovsky wrote:
Hello.

I'm trying to handle keypad keys depending on state of NumLock.
For example, if NumLock is ON and key KP_7 was pressed I call one function,
otherwise, if NumLock is OFF and key KP_7 was pressed I call another function.

Function SDL_GetModState returns zero.
Function SDL_GetKeyState returns for SDL_SCANCODE_NUMLOCKCLEAR also zero.

Is this a bug or there is a proper way to check the NumLock state?
Any advice would be much appreciated.
Re: NumLock state
bibendovsky


Joined: 06 Jun 2014
Posts: 2
[quote="AlexRou"]GetModState actually is working, its just that on startup the mod state is always off so when you press numlock while its on before starting the application the state gets reversed. You can either use platform specific methods to get the key state or use platform specific methods to toggle the LED so its off on start.

(SDL_GetModState() & KMOD_NUM) == (KMOD_NUM)

[quote="bibendovsky"]Hello.

Thanks for information. I will try it.
Re: NumLock state
.3lite


Joined: 25 Oct 2013
Posts: 38
I will bump this thread since it's definitely a bug in SDL2.

We have no way of knowing the real state of the numlock state, so basically if it's off then SDL2 is generating both SDL_TEXTINPUT and SDL_KEYDOWN events resulting in typing the text and navigating around (if numpad is used as arrow keys). However, only SDL_KEYDOWN events are send when the numlock is enabled. It is impossible to check the numlock state by using SDL_GetModState since it's always false when the application is started (even though the numpad is actually on).