# Create custom shortcut to change font color

Just wondering if I can create a custom shortcut key to change the font color of the notebook text.

I've created a custom shortcut (in dkyeventtransactions.tr) to bring up the font color dialog, as so...

Item[KeyEvent["q", Modifiers -> {Control}],
FrontEndExecute[FrontEndToken["FontColorDialog"]]]


but I'm hoping to create different shortcut keys to change the font directly to different colors, without using the font color selection dialog.

-
Is this what you are after? – Kuba May 8 '14 at 17:51
Thanks Kuba, this is very close, but it seems to have the effect of coloring all the characters in the line before the spot that I use it, rather than just change the color for the characters I type next. I your example below, if I were to use the press [Ctrl]-t after typeing dsf, it will change the dsf to red also. – mitcheljh May 10 '14 at 13:02

## 2 Answers

You have to add the following statement to the KeyEventTranslations.tr file:

Item[KeyEvent["t", Modifiers -> {Control}],
FrontEndExecute[
FrontEndSetOptions[
FrontEndNotebookSelection[ FrontEndInputNotebook[]],
FontColor -> RGBColor[1, 0, 0]]]]


Be careful: there are not many "free" letters available and when you use one that is already in use, it will not work :)

p.s. a more flexible solution is available with Shortcuts package and joker functionality, just proceed like in: 72914

-

One can change

MenuItem["Red",     FontColor->RGBColor[1, 0, 0]],


to, e. g.,

MenuItem["Red",     FontColor->RGBColor[1, 0, 0], MenuKey["r", Modifiers->{"Control"}]],
`

in the MenuSetup.tr file.

This has the additional advantage of adding the shortcuts to the menu for easier lookup.

-