To get this to work you have to use a third party tool: Karabiner.
In the example below the key combination cmdoptesc darkens the monitor.
- Download, install and open Karabiner
- Open in the menulet Karabiner -> Preferences
- Open the tab Misc & Uninstall
- Hit the button Open private.xml
- Open the file private.xml with an appropriate editor
Enter the customized keycode
<?xml version="1.0"?>
<root>
<item>
<name>Disable Command Option Escape</name>
<identifier>disable_cmd_alt_esc</identifier>
<autogen>__KeyToKey__ KeyCode::ESCAPE, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_OPTION, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_COMMAND, ConsumerKeyCode::BRIGHTNESS_DOWN</autogen>
</item>
</root>
Save the file
- Open in the menulet Karabiner -> Preferences the tab Change Key
- Hit the ReloadXML button
- Enable the remapping. It should be listed at the beginning.
You may refine the customized key code by adding a shortcut to brighten the monitor again to avoid a totally darkened screen and a helpless student sitting in front of it - unable to continue the test:
<?xml version="1.0"?>
<root>
<item>
<name>Disable Command Option Escape</name>
<identifier>disable_cmd_alt_esc</identifier>
<autogen>__KeyToKey__ KeyCode::ESCAPE, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_OPTION, ModifierFlag::COMMAND_L, ConsumerKeyCode::BRIGHTNESS_DOWN</autogen>
<autogen>__KeyToKey__ KeyCode::ESCAPE, MODIFIERFLAG_EITHER_LEFT_OR_RIGHT_OPTION, ModifierFlag::COMMAND_R, ConsumerKeyCode::BRIGHTNESS_UP</autogen>
</item>
</root>
In the first configuration each key combination (cmd_l/ralt_l/resc) darkens the screen. In the second configuration cmd_lalt_l/resc darkens and cmd_ralt_l/resc brightens the screen.
Karabiner also allows you to define application-only key codes. By adding your app to /Applications/Karabiner.app/Contents/Resources/appdef.xml or to private.xml you can restrict the customized key code to your app's realm. Below the <identifier>
tag you have to add a line <only>Your_App's_Name</only>
then.
Depending on your app you probably have to disable some other shortcuts too: e.g. cmdQ. Additionally you may have to hide Karabiner in the menubar.