Help - key code a function key (F2)

I am trying to key code a function key - F2. Looking around the web and on these forums indicates that I should be able to do it with the following applescript, but it does not seem to have any effect. I have the Apple Bluetooth keyboard if the matters. Any ideas?


	tell application "System Events"
		key code 120
	end tell

I am not 100% familiar with key codes and if they need key strokes or not.

But are you trying to use F2 with in a program? As in F2 does something within the app.

Because Appleā€™s shortcuts seem to override any functionality with the keys. Example if I want to take a screen shot in a Steam game (F12) it just puts up the volume and nothing else.

Just my thoughts there for you just incase sorry if its not any help.

Bruce

Hi pruppert,

If you have a laptop, then you fight need to press the fn key or set up your Preferences for function keys.

gl,
kel

Turns out the correct key code is 144. I figured this out by reading this page (http://superuser.com/questions/540799/sending-key-via-ssh-or-using-mouse-to-activate-target-display-mode), where the questioner was wanting to do the same thing as me - trigger target display mode on an iMac by using a script to remotely press the keyboard shortcut for target display mode.

There were so many references on the web saying that the F2 key code is 120, when it in fact appears to be 144. These key codes are surprisingly hard to track down.