Requirement

A "Visualization Manger" is added to the project automatically.
Add the library "VisuElemBase" as a top-level library in the "Library Manager".

Creating the EventHandler

The method "HandleKeyEvent" is created automatically with the FB:



Declaration

FUNCTION_BLOCK EventHandler IMPLEMENTS IKeyEventHandler
VAR_INPUT
END_VAR
VAR_OUTPUT
    udiKeyDownCount    :    UDINT;
END_VAR
VAR
END_VAR


Declaration

{warning 'add method implementation '}
(* This method will be called after a key event is released. 
 RETURN: 
 TRUE - When the handler has handled this event and it should not be handled by someone else
 FALSE - When the event is not handled by this handler*)
METHOD HandleKeyEvent : BOOL
VAR_INPUT
    (* The event type. The value is true if a key up event was released.*)
    bKeyUpEvent    : BOOL;
    (* The key code*)
    dwKey    : DWORD;
    (* The modifiers. Possible values are:
 VISU_KEYMOD_SHIFT :             DWORD := 1;
 VISU_KEYMOD_ALT :                 DWORD := 2;
 VISU_KEYMOD_CTRL :                 DWORD := 4;*)
    dwModifiers    : DWORD;
    (* A pointer to the client structure were tje event was released*)
    pClient    : POINTER TO VisuStructClientData;
END_VAR

Implementation

IF bKeyUpEvent THEN
    THIS^.udiKeyDownCount := THIS^.udiKeyDownCount + 1;    
END_IF

Instantiating the Eventhandler


Declaration

PROGRAM PLC_PRG
VAR
    instEvHandler    :    EventHandler;
    udiCurValue      :    UDINT;
END_VAR

Implementation

udiCurValue := instEvHandler.udiKeyDownCount;

Assigning the EventHandler to the visualization

In old versions, the following approach is not possible, because the assignment of a program from the visualization manager was not possible:
For these versions, an initialization must take place in the program code.


Declaration

PROGRAM VisuInit
VAR
END_VAR

Implementation

VisuElems.VisuElemBase.g_VisuEventManager.SetKeyEventHandler(PLC_PRG.instEvHandler);

Downloading and starting the project