Mon Jul 31 22:55:42 CEST 2006

Testing how keyboard works in Carbon, connecting it into

Warning: not everything in this blog entry is strictly true :-)

Carbon key codes... The image you see here has an interesting history... Yesterday, I extended my patch set I use for testing svdem sample application with a simple processing of key events. With simple, I really mean simple - in case of key event, it just prints all event parameters and does nothing else. Today I thought it could be interesting to actually do something ;-)

As I was not aware of any other piece of code than font dialog (svtools's svdem) that works now and should also work a bit better with keyboard, I wanted to implement cursor key down to be able to use keyboard to see all nice fonts we can display now even without X11 installed! Thus I first sent one SalEventKey with KEY_DOWN key on every key event (any key down, any key up or key repeat). I was happy to see cursor jumping down six times after pushing keys N, e and ? (I somehow forgot the last key, sorry for that) in sequence ;-)

OK, but this was still not quite enough - I decided that only real cursor down key should move the cursor down. So I "sniffed" the key code number for cursor down key (it is 125) and sent the event only in case of key down Carbon event. It worked. Adding cursor up was an immediate idea I have implemented (still being watched by Fridrich who was always a bit before me - because I actually had to type down all of our ideas ;-).

Then we realized, that the keyboard I have connected to my Mac mini has more than 100 keys and after one-second-long-dream of the "switch" command in the source we realized we need a table mapping key codes to actual keys ;-) Fridrich started to draw his own keyboard layout on the paper wanting to be better than this chap. After few lines and few letters, we both agreed he can't do that ;-) So he started the desktop with huge K and cog-wheel on its screen and finally found some keyboard layout image. Few minutes after it, Kendy admits that he actually is using the layout shown on that image (closer investigation revealed it was Dvorak's keyboard layout instead of QWERTY - no problem for me though).

"Interesting" work writing down key code of every key on my keyboard took me approximately half an hour - really productive work :-( You can click on the thumbnail of the image to get the full size image of the keyboard layout with all key codes written down (modulo Expose keys handled by window manager, and modifier keys and some other special keys probably forgotten by Apple on the drawing board when they designed their first keyboard).

Now seriously: my current svdem is able to scroll down using cursor keys and Page Up and Page Down keys. Good beginning. More later this week (read as: quick hack done, works, rewrite it from scratch with complete understanding of the problem area).

Posted by Pavel | Permanent link | File under:, Mac OS X