WLEvent.on()
Overview
Set an event handler (a function) for the current scope or a specified scope.
Added in version 1.2.0
Format
WLEvent.on(eventName, funcRef, scope, addFirst);
Parameter | Description | Type | Required | Notes |
---|---|---|---|---|
eventName | The name of the event. | String | Required | See Event Name Options below. |
funcRef | The function that runs when the named event is triggered. Functions should take one parameter that is an event object. | Function | Required | |
scope | The scope this event is added to. | String | Optional | If no value is provided, the current scope is used. See WLEvent.registerScope(). |
addFirst | Should the event should be inserted at the highest priority position. | Boolean | Optional | If no value is provided, this parameter defaults to false . |
Example
/* When a scanning event occurs for the session, the anonymous function is called.
*/
WLEvent.on("Scan", function(event) {
Logger.debug("Scan of data: " + event.data);
}, "session");
Event Name Options
The event object is passed as the first parameter to an event handler (a function). The event object can be used to get more information about the event. The event object can also be used to pass results back after processing.
"Beep"
Triggers the event when a beep is about to play.
Added in version 1.2.4
Event Property | Type | Description |
---|---|---|
type | String |
The beep type. "2" for an error beep, "3" for a scan beep, and "4" for a standard beep. |
eventHandled | Boolean | Can be set to disable default processing of this beep. |
"Connect"
Added in version 2.0.1
Triggers the event after a connection has been established to the host. The event object passed to "Connect" is empty.
"EnterScope"
When a scripting scope is entered. Fires after the scope is added to the scope stack, but before executing all functions registered for the scope.
Event Property | Type | Description |
---|---|---|
scope | String | The name of the scope entered. |
"ExitScope"
When a scripting scope has exited.
Event Property | Type | Description |
---|---|---|
scope | String | The name of the scope entered. |
"Key"
Triggers the event when a general purpose key handler is registered. All software and hardware presses will be sent for this event.
Event Property | Type | Description |
---|---|---|
keyCode | String | The decimal key code as a string. This property can be modified to change how this key is handled. |
eventHandled | Boolean | Can be set to disable default processing of this key. |
"NativeScreenTap"
Added in version 2.1.31
Triggers when the native screen is clicked or tapped. If the option Tap to Move Cursor is not enabled for the profile, this event is triggered, but the default action will be to discard the event.
Event Property | Type | Description |
---|---|---|
row | String | The row number that was tapped as a string. This property can be modified to change how this tap is handled. |
column | String | The column number that was tapped as a string. This property can be modified to change how this tap is handled. |
eventHandled | Boolean | Can be set to disable default processing of this tap. |
"Ndef"
Added in 2.1.23
Triggers the event when an NDEF NFC tag is scanned.
Starting in version 2.1.25, the API NFC.startCapture() must be used before NDEF events are dispatched.
Main event object
Event Property | Type | Description |
---|---|---|
id | String | The ID of the NFC tag that was scanned. |
ndefRecords | Array of NDEF record objects | Collection of NDEF records. |
ndefRecord object
Event Property | Type | Description |
---|---|---|
tnf | Number | The top level type for the NDEF record. |
type | string |
Indicates type with extra processing uri or text. Optional. |
text | string |
If type is set to text, this field is populated with the payload converted to a string. Optional. |
language | string |
If type is set to text, this field is populated with the language. Optional. |
uri | string |
If type is set to uri, this field is populated with the payload converted to a uri string. Optional. |
payload | ArrayBuffer | NDEF record payload. |
rawType | ArrayBuffer | NDEF record type. |
mimeType | string |
NDEF record MIME type. Optional. |
Example of emulating a scan from URI or text NFC tag
/*
This examples gets the first NDEF record, and checks first checks if the uri field is populated then sends a fakescan using the uri field. If the uri doesn't exist it tries the text field.
*/
NFC.startCapture();
WLEvent.on("Ndef",function(event){
if(event.ndefRecords[0].type === "uri"){
Device.fakeScan("nfc", event.ndefRecords[0].uri);
}else if(event.ndefRecords[0].type === "text"){
Device.fakeScan("nfc", event.ndefRecords[0].text);
}
});
Example of enumerating the records
/*
This examples enumerates multiple records emulating a scan.
*/
WLEvent.on("Ndef",function(event){
for(var i = 0; i<event.ndefRecords.length> ; i++){
if(event.ndefRecords[i].type === "text"){
Device.fakeScan("nfc", event.ndefRecords[i].text);
}
}
});
"OnKey<HHHH>"
When a registered key is pressed on either the software or hardware keyboard. This event takes precedence over the general-purpose Key
event. The values entered in place of “HHHH” must be a valid hex code. For example: OnKey<000D>
.
Event Property | Type | Description |
---|---|---|
keyCode | String | The decimal key code as a string. This property can be modified to change how this key is handled. |
eventHandled | Boolean | Can be set to disable default processing of this key. |
"ParseScreen"
Triggers the event when a screen is ready to be parsed. The functions in the event object can then be used to modify how the screen will be predicted. For an example of using the ParseScreen event, see Rapid modernization.
Added in version 2.0.0
Event Property | Type | Description |
---|---|---|
add(component) | Function | A function that can be called to add a component to the modernized screen. The component is inserted based on the row and column that were specified at the time of creation. |
addFunctionCall(functionName, [value1, value2, ...]) | function |
Links a function call to the modernized screen. Arguments are passed as an array of values. For example: ['Hello world', 123, true] Added in version 2.1.1 |
containsTextAt(row, column, text) | Function | A function that can be called to determine if text exists at the row and column specified. Returns true if the text is at the specified location. |
createSpanGroup() | Function | Returns a List Container . Typically used to horizontally align its child components. |
createHeader(row, column, title) | Function | Returns a component with text that will be emphasized on the screen. Typically used for titles or section headings. |
createFooter(row, column) | Function | Returns a List Container that is positioned at the bottom of the screen. Typically used to position buttons at the bottom of the screen. |
createDataLabel(row, column, label) | Function | Returns a label that is positioned relative to other components on the screen. |
createDataValue(row, column, length) | Function | Returns a text component with a value that is read directly from the native screen. |
createField(row, column, length) | Function | Returns an interactive component that accepts user input. The value of this component is normally read from the native screen. |
createMenuItem(row, column, label, command) | Function | Returns a menu component with the given label . The command string is sent to the host when this item is tapped. |
createButton(row, column, label, command) | Function | Returns a button component with the given label . The command string is sent to the host when this item is tapped. |
createShortcut(row, column, label, command) | Function | Returns a shortcut component with the given label . These components are added to the context menu of the user interface and never directly rendered to the screen. The command string is sent to the host when this item is tapped. |
createErrorMessage(row, column, message, title, command) | Function | Returns a message component. The command string is immediately sent to the host when this component is displayed. |
createWarningMessage(row, column, message, title, command) | Function | Returns a message component. The command string is immediately sent to the host when this component is displayed. |
createInfoMessage(row, column, message, title, command) | Function | Returns a message component. The command string is immediately sent to the host when this component is displayed. |
createBanner(title, imageSource) | Function | Returns a banner component that will be positioned at the top of the screen. |
createImage(row, column, imageSource) | Function | Returns an image component that will be positioned relative to other components on the screen. |
createTable(row, column, maxRows, maxColumns) | Function | Returns a Grid Container that will be positioned relative to other components on the screen. The table size is equal to maxRows * maxColumns . Use addToCell() to insert components within the correct cell of the table. |
createEmpty() | Function | Returns an empty cell that must be placed in the table to provide width for a collapsed column. |
getCursorPosition() | Function | Returns a cursor object with row and column properties. |
getTextAt(row, column, length) | Function | A function that can be called to get text at a specified row and column. The length parameter is optional, if not specified will continue to the end of the line. Returns a string containing the text. |
getAttributeAt(row, column) | Function | A function that can be called to get the attribute at a specified row and column. Returns an integer with bit fields for attributes. See below. |
markScreen(row column, length) | Function | A function that can be called to mark areas of the screen as invisible to the predictive engine, preventing additional processing as recognizing this area of the screen for other components. |
Properties for containers returned by createTable(), createFooter(), or createSpanGroup().
Container Property | Type | Description |
---|---|---|
add(component) | Function | A function that adds a component to a List Container . |
addToCell(component, row, column) | Function | A function that adds a component to a Grid Container . |
Properties for element formatting
After an element is created, it may be styled using the following methods. Styling is applied in a manner consistent with the screen editor.
Added in version 2.1.1
Formatting Property | Type | Description |
---|---|---|
setBold(flag) | Function | Adds bold styling to the element when the flag is true, otherwise the styling will be removed. |
setItalic(flag) | Function | Adds italic styling to the element when the flag is true, otherwise the styling will be removed. |
setUnderline(flag) | Function | Add underline styling to the element when the flag is true, otherwise the styling will be removed. |
alignLeft() | Function | Sets the text alignment to be left-justified for the element. |
alignRight() | Function | Sets the text alignment to be right-justified for the element. |
alignCenter() | Function | Sets the text alignment to be centered for the element. |
fontSize(pointValue) | Function | Sets the point size of the text where the largest point size is 72pt and the smallest is 6pt. If a value is used that does not match the list of sizes found in the console, that value will be rounded down to the nearest available size. e.g. Any value greater than 72 will be rounded down to 72, but 71 will be rounded down to 66. |
fontFamily(groupName) | Function | Selects a generic family of fonts used to display text. Must be one of the following values serif, sans-serif or monospace. |
backgroundColor(red, green, blue, alpha) | Function | Sets the background color for the element. RGB values are numbers between 0 and 255. The alpha channel is a value between 0.0 and 1.0, where 0.0 is fully transparent and 1.0 is fully opaque. |
fontColor(red, green, blue, alpha) | Function | Sets the text color for the element. |
Example of element formatting
ModernScreen.disablePredictive("Menu");
WLEvent.on("ParseScreen", function(event) {
if (event.containsTextAt(2, 3, "Outbound Pick")) {
var menuItem = event.createMenuItem(2, 3, "Outbound Pick", "3{AutoEnter}");
menuItem.setBold(true);
menuItem.setItalic(true);
menuItem.setUnderline(true);
menuItem.alignCenter();
menuItem.fontSize(24);
event.add(menuItem);
for (var i = 0; i < 7; i ++) {
event.markScreen(i, 0, 80);
}
}
});
Example of linking functions to screens
ModernScreen.disablePredictive("Menu");
WLEvent.on("ParseScreen", function(event) {
event.addFunctionCall("FUNCTION_NAME", ["VALUE1", VALUE2, ...]);
});
Attributes returned by getAttributeAt()
Attribute Bit(s) | Description |
---|---|
0x000000FF | Foreground color |
0x0000FF00 | Background color |
0x00010000 | Bold |
0x00020000 | Underline |
0x00040000 | Invert foreground/background |
0x00080000 | Blink |
0x00100000 | Italics |
0x00200000 | Hidden |
0x00400000 | Password |
0x00800000 | Strike-thru |
0x01000000 | Faint |
0x04000000 | Protected |
0x08000000 | Column |
Colors for foreground and background
Color Bits | Description |
---|---|
0x00 | Black |
0x01 | Red |
0x02 | Green |
0x03 | Yellow |
0x04 | Blue |
0x05 | Magenta |
0x06 | Cyan |
0x07 | Light Gray |
0x08 | Dark Gray |
0x09 | Bright Red |
0x0A | Bright Green |
0x0B | Bright Yellow |
0x0C | Bright Blue |
0x0D | Bright Magenta |
0x0E | Bright Cyan |
0x0F | White |
"Preconnect"
Triggered before connection to the host. This event can be used to alter host profile settings before the connection is made. This event is only triggered in the “beforeSession” scope. The event.connect() must be called if this event handler is registered, otherwise the host profile will never connect and will remain at the connecting screen.
Added in version 1.2.109
Event Property | Type | Description |
---|---|---|
name | String | The name of the profile. |
emulationType | String | The emulation type of the profile. e.g. “IBM-5251-11” or “VT220” (Read only) |
address | String | The address or URL that the profile will connect to. This property can be modified to change the data before connection. |
workstationId | String | The workstation ID of the profile. This property can be modified to change the data before connection. (Only for IBM type emulations.) |
answerBack | String | The VT answer back of the profile. This property can be modified to change the data before connection. (Only for VT type emulations.) |
port | Number | The port number of the profile. This property can be modified to change the data before connection. (Only for non-web emulations.) |
connect | Function | A function that must be called when modification to the profile is complete. The function takes a single Boolean parameter. If the parameter is true the connection will continue with any changes applied. If the parameter is false then the connection will fail with an error. |
connectProAddress0 | String | The address of the first ConnectPro server. This property can be modified to change the data before connection. You must have a ConnectPro server specified in the host profile in order to set this. |
connectProPort0 | String | The port of the first ConnectPro server. This property can be modified to change the data before connection. You must have a ConnectPro server specified in the host profile in order to set this. |
connectProAddress1 | String | The address of the second ConnectPro server. This property can be modified to change the data before connection. You must have a second ConnectPro server specified in the host profile in order to set this. |
connectProPort1 | String | The port of the second ConnectPro server. This property can be modified to change the data before connection. You must have a second ConnectPro server specified in the host profile in order to set this. |
connectProAddress2 | String | The address of the third ConnectPro server. This property can be modified to change the data before connection. You must have a third ConnectPro server specified in the host profile in order to set this. |
connectProPort2 | String | The port of the third ConnectPro server. This property can be modified to change the data before connection. You must have a third ConnectPro server specified in the host profile in order to set this. |
sshAutoLoginUser | String |
The SSH autologin user name. Added in 2.1.7. |
sshAutoLoginPassword | String |
The SSH autologin password. This value is write-only. You cannot use this to retrieve the password defined in the host profile. Added in 2.1.7. |
"QuickLaunch"
When the Quick Launch button is pressed.
Added in 2.1.11
Event Property | Type | Description |
---|---|---|
packageName | String | The name of the package to launch. |
"Scan"
When scan data is received from the scanner. This event may be used to alter scan data before it is sent to the host.
Event Property | Type | Description |
---|---|---|
data | String | The scan data. This property can be modified to change the data before it is sent. |
type | String | The symbology type. |
"ScreenUpdated"
When a TE screen update is received from the host system. There are no properties in the event object.
Added in version 1.2.104
"SpeechResult"
When a speech result is received from the voice recognition engine.
Added in version 1.2.104
Event Property | Type | Description |
---|---|---|
template | String | If a template has been selected this will contain the template name, otherwise it will be undefined . |
confidence | Number | The confidence level returned by the voice recognizer. |
grammar | String | The grammar that this speech result belongs to, may be undefined when the result is a voice command. |
startRule | String | The rule that this speech result belongs to, may be undefined when the result is a voice command. |
userId | Number | The assigned ID value from the grammar command !id. |
result | String | The value that should be sent to the host, this may be a key macro sequence as defined by a voice command. |
speechResult | String | The original value that was recognized by the voice engine. |
eventHandled | Boolean | Can be set to disable default processing of this event. |
"WebAlert"
This event is fired when a JavaScript alert is received by the browser. This event may be used to alter the alert message or use the speech engine to speak the alert text. The event also allows the JavaScript alert to be suppressed.
Added in version 2.1.7
Event Property | Type | Description |
---|---|---|
title | String | The title of the JavaScript alert. Can be read and set. |
message | String | The message of the JavaScript alert. |
suppressAlert | Boolean | Can be set to suppress the incoming alert. |
"WebDownload"
This event is fired when a download would occur in the Android web browser. This event may be use to override the default handling of the download. The default handling launches the default viewer for PDF files on the Android device.
Added in version 2.1.21
Event Property | Type | Description |
---|---|---|
url | String | The URL of the content to be downloaded. |
mimetype | String | The MIME type of the content. |
eventHandled | Boolean | Set to true to disable default processing of this event. |