How to map the “Eject” key on a Microsoft keyboard or create a new shortcut for locking the screen

keyboardshortcut

I like using Control + Shift + Eject to lock my screen quickly. The Eject key does not exist on my Microsoft keyboard, and there does not seem to be easy way to do map another key to that key through System Preferences.

  • How can I map a key on my Microsoft keyboard to the Eject key?
  • Otherwise, how do I create a new shortcut for locking my screen?

Best Answer

I don't know how to map a key to the Eject key, but you can easily create a new shortcut with Automator and Services:

  1. Open Automator in the Applications folder.

  2. Choose Service:

    enter image description here

  3. Select Utilities and drag Run AppleScript to the right pane:

    enter image description here

    Configure, on the top right corner, that the service should receive no input in any application. Then paste this AppleScript script:

    on run {input, parameters}
        do shell script "open /System/Library/Frameworks/ScreenSaver.framework/Versions/A/Resources/ScreenSaverEngine.app"
    end run
    
  4. Save the service. Use a descriptive name, as it is the name that will appear in the Services menu. You can see in the screenshot above that I named the service Lock Screen.

  5. Open System Preferences, select Keyboard and then the Shortcuts tab. Under General locate Lock Screen and assign a key shortcut to it. As you can see, I chose ControlCommandL:

    enter image description here

  6. The Lock Screen service is now accessible from any application as an entry in the Services menu:

    enter image description here

Choose the service shortcut carefully to avoid conflicts with other applications' shortcuts.