Switch to Target Display Mode without keyboard Here's my setup:  MacBook --> Thunderbolt Display --> iMac 27"

The MacBook is the primary computer I want to use;  the iMac is the (external) display.

This all works just fine.  The problem is, when I disconnect and then reconnect the MacBook, I have to manually put the iMac in Target Display Mode using the keyboard.  This means I need to keep a keyboard attached to the iMac, and it clutters up my desk!

Is there any way to switch the iMac into TDM without using the keyboard?  Maybe by logging in remotely?

I found a few similar questions, but... no answers!

Is it possible to have an iMac maintain target display mode even through sleep/screensaver

Target Display Mode: how to automate and persist on closing laptop

Anyone?
I found a way to do it with an old, white apple keyboard, haven't tested with others but it might work.

I used a tool called Karabiner from https://pqrs.org/osx/karabiner/. When you install it, enable following options to get Command + F2 to work:

F1..F12 to Functional Keys (Brightness Adjust, Music Control, etc)
- F1,F2 to Brightness Adjust
--- F1 to Brightness Down
--- F2 to Brightness Up


After enabling this option, hit Command + F2 having previously connected your macbook using thunderbolt cable. If you're lucky you'll have a new external display working!