# Automatic replacing of [ with []

I tried to modify the KeyEventTranslations.tr file in order to always place a closed bracket instead of an open bracket once I press [. However once I press [ after the modification nothing happens (the cursor just stays at the same position and not even a [ is placed).

Item[KeyEvent["["],
FrontEndExecute[{
FrontEndNotebookWrite[FrontEndInputNotebook[],
"[", After],
FrontEndNotebookWrite[FrontEndInputNotebook[],
"]", Before]
}]],


the Code is a slight modification of what i found regarding double brackets:

Automating Esc [[ Esc formatting?

(There is a comment below the top answer, which also mentions Problems regarding [ and German keyboard language).

If I use a different character like / to trigger the KeyEvent, which does not have to be typed using the AltGr-key

Item[KeyEvent["/"],
FrontEndExecute[{
FrontEndNotebookWrite[FrontEndInputNotebook[],
"[", After],
FrontEndNotebookWrite[FrontEndInputNotebook[],
"]", Before]
}]],


the closed bracket will be placed as expected. Other keys like { using AltGr do not work either.

I tried renaming the term.dll files as suggested here:

Is it possible to get AltGr key to work in Math.exe?

unfortunately this did not fix the Problem.

Additional Information: I'm using Win7 and my keyboard language is set to German. (And I would like to keep it set to German).

If there is any other way circumventing the KeyEventTranslations.tr to automaticaly place [] with the cursor placed between the brackets once I press [, it would be fine as well.

Are aware of the fact that Alt-] inserts a matching [ ] pair? No modifications necessary. –  Sjoerd C. de Vries Apr 13 '14 at 13:17
With keyboard language set to german that does not work for me. Pressing AltGr-Alt-8 (AltGr-]) does not yield any front end input for me. As a side note: Pressing Ctrl-Alt is equivalent to pressing AltGr on my keyboard. –  Max1 Apr 13 '14 at 13:50
With exception to basic editing and saving commands (Ctrl-A, Ctrl-S etc.) keyboard shortcuts do not work when keyboard locale is not set to English. Also the FrontEnd generally cannot handle correctly characters outside of Unicode level 0. –  Alexey Popkov Apr 13 '14 at 16:05
How about using FrontEndExecute[FrontEndToken["InsertMatchingBrackets"]] instead of the two FrontEndExecutes you used? –  Sjoerd C. de Vries Apr 13 '14 at 16:12
@SjoerdC.deVries I just tried, but it did not work. The problem is probably the KeyEvent["["]. In case there exists no proper solution I will just map [] to ), since I mapped () to ( I dont really need the ) key anymore. –  Max1 Apr 13 '14 at 16:47