Skip to main content

Object and page events

An event script runs when the operator does something with an object or the page on the run screen. You set it on the Events tab of PROPERTIES; see Client scripts. Event names are shown as they are, not translated.

Object events​

EventOffered onFires when
onClickAll objectsThe left mouse button is released without dragging
onMiddleClickAll objectsThe middle mouse button is clicked
onRightClickAll objectsThe right mouse button is clicked (context menu)
onDblClickAll objectsThe object is double-clicked
onMouseEnterAll objectsThe pointer enters the object
onMouseLeaveAll objectsThe pointer leaves the object
onMouseDownAll objectsA mouse button is pressed on the object
onValueChangeInput, Select, Switch, SliderThe value changes; on an input at every keystroke and again when it is confirmed
onKeyDownInputA key is pressed in the input
onKeyUpInputA key is released in the input
onFocusInput, SelectThe control gets the focus
onBlurInput, SelectThe control loses the focus

For the left, middle and right click, the Events tab also offers a click Action and opening or closing a popup without a script; see Click actions.

Page events​

The page has four events, on the page background (where no object is): onClick, onDblClick, onMouseEnter and onMouseLeave. Opening and leaving a page are not events: use a page script with the trigger onLoad or onUnload.

The handler​

A handler is an async function in project_main.js that receives the event:

async function Overview_StartButton_onClick(event) {
if (await UI.confirm("Start pump P101?")) {
await Tag("P101.Start").write(true);
}
}
event fieldMeaning
type, target, elementIdEvent name, target and the identifier of the object
x, yPosition within the object
clientX, clientYPosition on the screen
buttonMouse button: 0 left, 1 middle, 2 right
key, codeKey of a keyboard event
altKey, ctrlKey, shiftKeyModifier keys held
value, prevValueNew and previous value of an input; otherwise the value of the signal bound to the object

In the handler, self is the object itself: reading a property gives its current value, assigning one changes it on the screen for as long as the page is open (self.fill = "@alarm_critical"). In a popup, modal is that popup with its data and close(). All client script functions are available.

Put code that several event handlers share in project_main.js.

Page script triggers​

Page scripts run without an operator action. Each page script has a Trigger:

TriggerRuns
onLoadOnce when the page opens
onUnloadOnce when the page is left; timers and screen changes made by scripts are cleared right after it
PeriodicEvery Interval (ms), at least 500 ms; a run is skipped while the previous one is still going
Tag ChangeWhen the signal in Tag Name changes; checked every 500 ms, the first value only sets the starting point

The page's <page>_main.js runs when the page opens, like onLoad. Order when a page opens: the scripts of the previous page stop (onUnload), the libraries are loaded, <page>_main.js runs, then the triggers start. If only the objects of the page changed, the scripts are not restarted.