Enable Function Key Lock when using external keyboard/Disable when using internal keyboard on Mac Book Pro
To make this work you have to use a third party tool: Karabiner.

To enable this you have to create a filter for the external keyboard and invert all function/consumer keys.

Prerequisites:


Download, install and open Karabiner
Open in the menulet Karabiner -> Preferences
Open the tab Misc &amp; Uninstall
Hit the button Launch EventViewer
Hit the tab Devices
Make a note of the vendor and product ID of the external keyboard
Close the EventViewer
Hit the button Open private.xml
Open the file private.xml with an appropriate editor
Enter the customized keycode and replace the vendor and product ID by IDs found above

&lt;?xml version="1.0"?&gt;
&lt;root&gt;
  &lt;devicevendordef&gt;
    &lt;vendorname&gt;Apple&lt;/vendorname&gt;
    &lt;vendorid&gt;0x05ac&lt;/vendorid&gt;
  &lt;/devicevendordef&gt;
  &lt;deviceproductdef&gt;
    &lt;productname&gt;ExternalKeyboard&lt;/productname&gt;
    &lt;productid&gt;0x0256&lt;/productid&gt;
  &lt;/deviceproductdef&gt;
  &lt;item&gt;
    &lt;name&gt;Function to Consumer for External Keyboard&lt;/name&gt;
    &lt;identifier&gt;private.function2consumerExtK&lt;/identifier&gt;
    &lt;device_only&gt;DeviceVendor::Apple, DeviceProduct::ExternalKeyboard&lt;/device_only&gt;
    &lt;autogen&gt;__KeyToKey__ KeyCode::F1, ConsumerKeyCode::BRIGHTNESS_DOWN&lt;/autogen&gt;
    &lt;autogen&gt;__KeyToKey__ KeyCode::F2, ConsumerKeyCode::BRIGHTNESS_UP&lt;/autogen&gt;
    ...
  &lt;/item&gt;
  &lt;item&gt;
    &lt;name&gt;Consumer to Function for External Keyboard&lt;/name&gt;
    &lt;identifier&gt;private.consumer2functionExtK&lt;/identifier&gt;
    &lt;device_only&gt;DeviceVendor::Apple, DeviceProduct::ExternalKeyboard&lt;/device_only&gt;
    &lt;autogen&gt;__KeyToKey__ KeyCode::BRIGHTNESS_DOWN, ModifierFlag::FN, KeyCode::F1&lt;/autogen&gt;
    &lt;autogen&gt;__KeyToKey__ KeyCode::BRIGHTNESS_UP, ModifierFlag::FN, KeyCode::F2&lt;/autogen&gt;
    ...
  &lt;/item&gt;
&lt;/root&gt;


Replace the ellipses by all other necessary consumer and function keys
Save the file
Open in the menulet Karabiner -> Preferences the tab Change Key
Hit the ReloadXML button
Enable the remappings. They should be listed at the beginning.


The final behavior should be as following with the function lock activated:

Internal keyboard:

F1: F1
Fn+F1: brightness up

External keyboard:

F1: brightness up
Fn+F1: F1

etc.

If you disable or skip the Consumer to Function for External Keyboard part it should act like this:

F1: brightness up
Fn+F1: brightness up  

which means that the "function key layer" is disabled and only the consumer key layer is working.

etc.



Other possible keycodes:

KeyCode::EXPOSE_ALL,                 KeyCode::F3&lt;/autogen&gt;
KeyCode::DASHBOARD,                  KeyCode::F4&lt;/autogen&gt;
KeyCode::LAUNCHPAD,                  KeyCode::F4&lt;/autogen&gt;
ConsumerKeyCode::KEYBOARDLIGHT_LOW,  KeyCode::F5&lt;/autogen&gt;
ConsumerKeyCode::KEYBOARDLIGHT_HIGH, KeyCode::F6&lt;/autogen&gt;
ConsumerKeyCode::MUSIC_PREV,         KeyCode::F7&lt;/autogen&gt;
ConsumerKeyCode::MUSIC_PLAY,         KeyCode::F8&lt;/autogen&gt;
ConsumerKeyCode::MUSIC_NEXT,         KeyCode::F9&lt;/autogen&gt;
ConsumerKeyCode::VOLUME_MUTE,        KeyCode::F10&lt;/autogen&gt;
ConsumerKeyCode::VOLUME_DOWN,        KeyCode::F11&lt;/autogen&gt;
ConsumerKeyCode::VOLUME_UP,          KeyCode::F12&lt;/autogen&gt;