Friday, 4 December 2015

SDL 2.0: Scancode and keycode

Graphics routines are now complete. What they mostly needed was alpha channel data for things like font colors, because everything starting from data is now 32 bit RGBA. The old update rectangles are gone, because SDL2 has (I guess?) only window wide update. In that I'm planning to use a trick where the screen is updated in the keyboard get routine, because that's how the program works in logical sense. That way I don't even have to keep a update flag for every single drawing routine would otherwise had to send to GUI. Just update when waiting for keypress, whether it's in a menu or during gameplay.

Keyboard routines also needed some work. The old unicode seems to be gone and now there are keycode and scancode codes for keys. I'm actually little bit confused about them and the way I wrote new keyboard routines was using keycode. But you have to do some funny things, because in Finnish key layout some keys are not where you would think they are. For example ? is shift-+ and greater/less than characters are in the same key with greater than requiring shift. To get ? I have to check for + with modifier key shift. But I'm not sure if it's the proper way. Will it work in other layouts as well? I'm also puzzled about scancode in 2.0, because I guess it's supposed to be the physical keyboard code, but keycode itself works pretty much like it already.

There were couple of other odd things. For some reason GetKeyName returns uppercase letter for letters, even keycodes are lowercase (SDLK_a='a'). More confusingly the keyboard event seems to receive lots of events when you press a key, but movement and everything else seems to work with normal repeat rate.

Now when the technical work is done it's time to return to content creation which is sometimes annoying. It's mostly technical as well, but you don't have any kind of reference or wiki for that.

No comments: