All base elements and some common control elements have the “Input configuration” property. This is where you can configure a user input for an element. For this purpose, you select an input event and an input action.
Configuring user inputs
Requirement: A project is open with a visualization.
-
Open the visualization and added a “Button” element.
The “Properties” view opens for the new button.
-
Configure the property “Text” with
Number of clicks: %i
.
-
Declare a variable
iClicks : INT;
in the application in thePLC_PRG
POU. -
Configure the “Text variable” property of the button as
PLC_PRG.iClicks
.At runtime, its variable value will replace the placeholder in the “Text” property.
-
In the “Input configuration” property, click the “Configure” button in the
OnMouseClick
line. -
Select the
Execute ST code
action from the list of possible actions and click thesymbol.
The action appears in the list of actions to be executed. The blank implementation of the action appears in the window area to the right of the list.
-
Program the action in the editor at “Execute ST code”:
PLC_PRG.iClicks := PLC_PRG.iClicks + 1;
-
Click “OK” to close the dialog box.
The user input is configured.
-
Compile, download, and start the application.
The application runs. The visualization opens. If the user clicks the button, then the action is executed, the variable
PLC_PRG.iClicks
is incremented, and the number of clicks is printed.