MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Keyboard shortcuts

  • To: mathgroup at smc.vnet.net
  • Subject: [mg23091] Re: Keyboard shortcuts
  • From: "Atul Sharma" <atulksharma at yahoo.com>
  • Date: Sun, 16 Apr 2000 00:37:32 -0400 (EDT)
  • References: <8d96sb$ii3@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Some time ago, Paul Hinton of WRI was kind enough to forward a recipe for
remapping the keyboard. I enclose it here:

A. Sharma
--------------------------------------------------
Atul Sharma MD, FRCP(C)
Pediatric Nephrologist,
McGill University/Montreal Children's Hospital
----------------------------------------------------------------------------
-----

Under Mathematica 3.0 and 4, keystroke sequences are associated with
actions by way of a Mathematica text resource file named
KeyEventTranslations.tr.

The file is installed deep within the core Mathematica tree in the
directory.

ToFileName[{$TopDirectory, "SystemFiles", "FrontEnd", "TextResources"}]

because Microsoft Windows uses different keymapping conventions, a
platform-specific version of this file can be found in:

ToFileName[{$TopDirectory, "SystemFiles", "FrontEnd", "TextResources",
  "Windows"}]

The structure of the file looks something like this:

[begin file schematic]
@@resource KeyEventTranslations

EventTranslations[<list of Item[] expressions>]
[end file schematic]

An individual Item[] expression contains two arguments.

Item[KeyEvent[<event name>], <front end action>]

The argument to KeyEvent[] is a key name.  Alphanumeric keys are
represented as strings.  Function and motion keys are referred to by
symbols that usually parallel their labeled name.  For example, the act of
typing the K key by itself is represented as

KeyEvent["k"]

However, a key such as the right arrow cursor movement key will look like

KeyEvent[Right]

Most of the non-alphanumeric keys are associated with events in
KeyEventTranslations.tr, so it is probably no necessary for you to guess
at the key's name.

KeyEvent[] expressions support two options.

Modifiers, which takes a list of modifier key names as its value.  These
are keys that must also be depressed with the primary key to acutate the
event.  For example, to denote Ctrl-I, you could enter the following:

KeyEvent["i", Modifiers -> {Control}]

Modifier key names are Shift, Control, Command, and Option.  On a
Macintosh, these map to keys with the same name.  Under X Window, Command
maps to Mod1 and Option maps to Mod2.  On Microsoft Windows, Command maps
to the Alt key, and the Control key maps to itself.

If you want an action to take place only within a cell that uses
two-dimensional boxes (StandardForm or TraditionalForm), then you can add
an option named CellClass and give it the value BoxFormData.  In this
example, pressing Ctrl-Left Arrow will apply only in cells which use
StandardForm or TraditionalForm.  It will not apply to plain text cells or
InputForm.

KeyEvent[Left, Modifiers -> {Control}, CellClass -> BoxFormData]

The action that appears in the second argument can be either a command
token in the form of a string (e.g. "CreateInlineCell"), or a function
that contains only front end manipulation functions.

The actions listed in the Item[] expressions of KeyEventTranslations.tr
should give you a clue as to some of the tokens available.  You can also
look in the directory

ToFileName[{$TopDirectory, "SystemFiles",
   "FrontEnd", "TextResources",
   LinkWrite[$ParentLink, FrontEnd`Value["$SystemID"]];
    LinkRead[$ParentLink]}]

for a file named MenuSetup.tr.  A similar mechanism allows the association
of menu item listings and front end commands.

A more exhaustive listing of front end command tokens can be found in
Chapter 56 of the book _The Beginner's Guide to Mathematica Version 3_ by
Jerry Glynn and Theodore Gray.

Let's now work through an example.  Suppose we wanted to define a keyboard
shortcut for initiating the File -> Save As Special -> EPS menu command
and map it to Ctrl-q.  Here is what the item may look like.

Item[
KeyEvent["q", Modifiers -> {Control}],
FrontEndExecute[{
FrontEndToken[
FrontEnd`InputNotebook[],
"SelectionSaveSpecial",
"EPS"
]
}]
]

The three-argument form of FrontEndToken[] is documented in Gray and
Glynn.  This is probably one of the more complicated examples that one
could devise.

If you do not have the necessary permissions to edit the
KeyEventTranslations.tr file, you can create a folder with path:

ToFileName[{$PreferencesDirectory, "SystemFiles",
   "FrontEnd", "TextResources",
   LinkWrite[$ParentLink, FrontEnd`Value["$SystemID"]];
    LinkRead[$ParentLink]}]

and then copy the KeyEventTranslations.tr file from your Mathematica
installation into your newly created directory.  Make your changes to that
file, and they will apply only to your own setup.


Felix E. Klee wrote in message <8d96sb$ii3 at smc.vnet.net>...
>Hi,
>
>I would like to change the keyboard short cuts in Mathematica 4
>for Linux.
>
>Where can I find information on how to do it?
>
>TIA,
>
>Felix
>



  • Prev by Date: Re: breaking up lists into intervals
  • Next by Date: Plotting bounded domains
  • Previous by thread: Re: Keyboard shortcuts
  • Next by thread: Equivalent to Mesh->False in ParametricPlot3D?