NotebookEventActions

NotebookEventActions

is a notebook option that gives a list of actions to perform when specified events occur in connection with the notebook.

Details

  • NotebookEventActions->{"event1":>action1,"event2":>action2,} specifies that actioni should be evaluated whenever "eventi" occurs in connection with the notebook.
  • The possible event specifications are the same as for EventHandler, with the following addition:
  • "WindowClose"window being closed
  • Settings for NotebookEventActions are often defined at the level of stylesheets, rather than for individual notebooks.
  • By default, any action specified for an event by NotebookEventActions will override any default action that the Wolfram System would take for that event.
  • The default behavior can be changed by including rules for PassEventsDown or PassEventsUp in the list given as the setting for NotebookEventActions.

Examples

open allclose all

Basic Examples  (1)

Set up a certain action to take place when a notebook is closed:

With the notebook open, k is unchanged:

When you close the notebook window, k is incremented:

Scope  (3)

Create a notebook window:

Set NotebookEventActions so that the notebook will change color when clicked:

Clicking the notebook changes its background:

Make an action occur when the TemplateBox[{return}, Key0, BaseStyle -> {ExampleText, FontWeight -> Plain, FontFamily -> Source Sans Pro}] key is pressed:

Define actions for "MouseDown" and "MouseUp":

The background will be pink only while the mouse button is held down:

After the mouse is released, the notebook is back to its normal background:

Possible Issues  (3)

This NotebookEventActions setting blocks the normal TemplateBox[{return}, Key0, BaseStyle -> {ExampleText, FontWeight -> Plain, FontFamily -> Source Sans Pro}] key behavior:

Pressing TemplateBox[{return}, Key0, BaseStyle -> {ExampleText, FontWeight -> Plain, FontFamily -> Source Sans Pro}] changes the background but does not start a new line:

This inserts a newline as part of the action specified for "ReturnKeyDown":

Pressing TemplateBox[{return}, Key0, BaseStyle -> {ExampleText, FontWeight -> Plain, FontFamily -> Source Sans Pro}] in this notebook inserts a newline as well as setting the background:

Specify a NotebookEventActions setting that goes away after being activated once:

A single TemplateBox[{return}, Key0, BaseStyle -> {ExampleText, FontWeight -> Plain, FontFamily -> Source Sans Pro}] changes the background without entering a newline:

Also, NotebookEventActions has been reset to None:

Now, more TemplateBox[{return}, Key0, BaseStyle -> {ExampleText, FontWeight -> Plain, FontFamily -> Source Sans Pro}] keystrokes add new lines as usual:

Introduced in 2007
 (6.0)