Copy and paste the code into ExtendScript Toolkit.
This utility can be found:-
PC: C:\Program Files\Adobe\Adobe Utilities
MAC: <hard drive>/Applications/Utilities/Adobe Utilities
Save the script to the following folder:-
PC: C:\Program Files\Adobe\Adobe Photoshop CS5\Presets\Scripts
MAC: <hard drive>/Applications/Adobe Photoshop CS5/Presets/Scripts
N.B. if your are using Vista or Windows 7 you will need to save the script elsewhere and then copy it to the relevant folder, this is due to permissions.
If Photoshop was open close and restart it so that it can pick up the new script.
To assign an action and function key, start recording a new action, assign the function key you require, then from the action palette fly-out menu select "Insert Menu Item" now File - Scripts and select your new script. Stop the recording.
Now every time you press the function key it will run the script.
Hope this helps.