# Turn PasteButton into keyboard shortcut

I'm looking for a general "recipe" to do with a keyboard shortcut what I currently do with a PasteButton. Here is a working toy example PasteButton:

PasteButton[Subscript[Ω, \[SelectionPlaceholder]]]


It generates a capital Greek letter Omega (type in as \[CapitalOmega]) with a selection placeholder (black square) in the subscript.

To "keyboard-shortify" it, I know that I have to modify the file KeyEventTranslations.tr in

OS-dependent/Mathematica/11.0/SystemFiles/FrontEnd/TextResources/

but what I have to put into this file is a lot more complicated than just copying from how the PasteButton does it.

If I wanted just the Ω without the subscript, associated with the keyboard stroke Control-Shift-Command-O, I would have to put the following:

Item[
KeyEvent["O", Modifiers -> {Control, Command, Shift}],
FrontEndExecute[{
FrontEndNotebookWrite[
FrontEndInputNotebook[],
"Ω",
After
]
}]
]


but what I tried putting into the .tr file with Subscript did not work - it always put Subscript[something] literally into the current notebook

I tried to write some code with SelectionMove[] and SelectionEvaluate[] and putting that into the .tr file, but it didn't work properly, and was awfully hard to test (restarting Mathematica all the time)

A more-than-ideal answer would be a function to which you supply, say, Subscript[Ω, \[SelectionPlaceholder]] as an argument, and which generates the string to be put into the .tr file as result.

Side question: Is there a way to test the code later being put into the .tr file without restarting Mathematica all the time?

• Here is an alternative solution: mathematica.stackexchange.com/q/164653/5478 – Kuba Jun 14 at 5:22
• Be careful. You should never modify core installation files. Copy them to the equivalent file in \$UserBaseDirectory and edit that copy. – b3m2a1 Jun 14 at 6:18
• Also, @b3m2a1 has a great package for the creation of custom KeyEvents! I’ll say also to avoid any combos that are superseded by the FrontEnd menus, too. They won’t work, or won’t work well. – CA Trevillian Jun 14 at 11:23

Why not use an InputAutoReplacements instead? For example:

CurrentValue[EvaluationNotebook[], {InputAutoReplacements, "ww"}] = "Ω"


Then you can type: w w Control+- to enter the desired subscript.

If you really want to use KeyEventTranslations.tr to do this, then you need to enter boxes:

Item[KeyEvent["O", Modifiers -> {Control, Command, Shift}],
FrontEndExecute[
FrontEndNotebookWrite[
FrontEndInputNotebook[],
SubscriptBox["Ω", "\[SelectionPlaceholder]"],
Placeholder
]
]
]

• What I settled for is InputAliases. The Omega with index was just a toy example, what I actually wanted is very similar to what is already existing, and which can be seen using CurrentValue[EvaluationNotebook[], InputAliases] – mathheadinclouds Jun 14 at 11:17
• Carl, the boxes method makes sense, so this should work for a combo of, say Ctrl+Alt/Cmd+’ for a SuperscriptBox["\[SelectionPlaceholder]","\[Prime]"] KeyEventTranslations? Same for Ctrl+Alt/Cmd+Shift+" and [DoublePrime]? Just checking for clarity. – CA Trevillian Jun 14 at 11:17
• @Trevillian, yes that works, just tried it - I think I'm actually going to keep this in my KeyEventTranslations. – mathheadinclouds Jun 14 at 11:44