Macbook key codes and validating the new keyboard keys

Recently I bought a new keyboard (see below) on Amazon for Macbook pro. I needed another cheaper keyboard when I might use it with wall mounted monitor near a tread mill. It is a knock off of Mac’s magic keyboard.  Interestingly it has both bluetooth and wireless (2.4G) connectivity while having all the four keys Fn, Ctrl, Option and Cmd keys in the same order.  Many of the third party mac keyboards either miss Fn key or place it near number keys and many other place them in Windows compatible keyboard order which is not ideal.

macbook_keyboard

This keyboard worked well but for one major issue – Esc key didn’t act the way one expected.  Nothing was happening and in “Vim” editor it is one of the most often used key.  I needed to either fix or identify the right key code it is generating or map it to new code or return the item.  I knew what ascii code (dec. 27) and key code (53) I should expect on pressing the key.  Here are the corresponding codes.

Read More »