({{, (RefLink[CellEventActions, paclet:ref/CellEventActions]) 
is an option for (RefLink[Cell, paclet:ref/Cell]) that gives a list of actions to perform when specified events occur in connection with a cell in a notebook. }})

OpenersNotesSection(Spacer1)Details

(RefLink[CellEventActions, paclet:ref/CellEventActions])->{"(Subscript[event, 1])":>(Subscript[action, 1]),"(Subscript[event, 2])":>(Subscript[action, 2]),…} specifies that (Subscript[action, i]) should be evaluated whenever "(Subscript[event, i])" occurs in connection with a cell.

The possible event specifications are the same as for (RefLink[EventHandler, paclet:ref/EventHandler]).

Settings for (RefLink[CellEventActions, paclet:ref/CellEventActions]) are often defined at the level of stylesheets, rather than for individual cells or notebooks.

By default, any action specified for an event by (RefLink[CellEventActions, paclet:ref/CellEventActions]) will override any default action that the Wolfram System would take for that event.

The default behavior can be changed by including rules for (RefLink[PassEventsDown, paclet:ref/PassEventsDown]) or (RefLink[PassEventsUp, paclet:ref/PassEventsUp]) in the list given as the setting for (RefLink[CellEventActions, paclet:ref/CellEventActions]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (3)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

Create a cell that will change color when you click within the cell:

CellPrint[TextCell["Click within this cell","Output",Background->LightRed,CellEventActions->{"MouseClicked":>(CurrentValue[EvaluationCell[],Background]=RandomColor[])}]];

OpenersExampleSection1(Spacer1)Scope  (1)

Make an action occur when the (Key0[MacOSXreturnenter]) key is pressed in a cell:

CellPrint[TextCell["Click in this cell and press Enter","Text",CellEventActions->{"ReturnKeyDown":>(CurrentValue[EvaluationCell[],Background]=LightGreen)}]];

Click in this cell and press Enter

OpenersExampleSection2(Spacer1)Options  (1)

OpenersExampleSubsection0(Spacer1)PassEventsDown  (1)

Normally, setting the "MouseClicked" handler prevents you from selecting a cell:

CellPrint[TextCell["This cell is not selectable","Output",Background->LightRed,CellEventActions->{"MouseClicked":>(CurrentValue[EvaluationCell[],Background]=RandomColor[])}]]

Create an event handler that triggers on a click but still allows selection to occur:

CellPrint[TextCell["This cell is selectable","Output",Background->LightRed,CellEventActions->{"MouseClicked":>(CurrentValue[EvaluationCell[],Background]=RandomColor[]),PassEventsDown->True}]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[EventHandler, paclet:ref/EventHandler])  ▪  (RefLink[NotebookEventActions, paclet:ref/NotebookEventActions])  ▪  (RefLink[FrontEndEventActions, paclet:ref/FrontEndEventActions])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Low-Level Interface Control, paclet:guide/LowLevelInterfaceControl])}, {▪(RefLinkPlain[Custom Interface Construction, paclet:guide/CustomInterfaceConstruction])}, {▪(RefLinkPlain[Stylesheets, paclet:guide/Stylesheets])}})}})