Adds simple auto-detection of keyboard layout on Mac OS X.
All detected layouts have been tested with the standard mac keyboard layouts.
Note that the mac layouts put some keys in different places compared to typical PC layouts, like backslash on scandinavian keyboards.
Fix a potential memory leak in the patch first uploaded