The HTML example can be copied and saved as an HTML page with an editor. This page can be stored in the HTML directory of the SiteKiosk installation folder. Next set the page in the configuration of SiteKiosk as the start page for testing and configure at least one input device. Save the configuration and then launch SiteKiosk. On the test page, a listener can be set for the configured device to read the data from the device and display it on the page.
The sample code can be modified and used on any Web page to work with the data read from the device.
2.1 Internet Explorer based skins
The following script example is for the IE based browser skins of SiteKiosk.
To call the script within frames, the line
window.external.InitScriptInterface(); in
window.external.InitScriptInterface(document); must be changed.
Using the
SiteKiosk Object Model and the method
SiteKiosk.RootApp.registerForDeviceData it is possible to register a listener that waits for input a specific device and then makes them available.
To do this, use the following
SiteKiosk Object Model method:
SiteKiosk.RootApp.registerForDeviceData(deviceName, callbackFunc) |
deviceName =
The display name of the device in the configuration (String)
callbackFunc = N
ame of the function that is called after the reading of data (String)
The callbackFunc function has two parameters. The data that has been read as a string and also the name of the device from which the data was read.
Example:
The following example is an HTML page with a text box that is set up in the SiteKiosk configuration to activate the listener for a device name with a button click. It then reads data on the selected device which is displayed on the page. Please keep in mind that you need to give the URL that uses the SiteKiosk Object Model code
script permission under Access/Security.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Keyboard Emulation Device Test</title>
<script>
window.external.InitScriptInterface();
var callbackFunc = function (data, devicename) {
document.getElementById("text").innerHTML =
"Data received from device with the name: "
+ devicename + ". Data: " + data;
};
function registerDevice() {
var deviceName = document.
getElementById("devicename").value;
if(deviceName == "")
return document.
getElementById("foundDevice").
innerHTML = "The device name is empty!";
SiteKiosk.RootApp.
registerForDeviceData(deviceName, callbackFunc);
return document.getElementById("foundDevice").
innerHTML = "Registered device: " + deviceName;
}
</script>
</head>
<body>
<h1>Test page for reading the input of keyboard
emulation devices configured in the configuration
of SiteKiosk</h1>
<div>
Listen to input from this device that has been
configured in SiteKiosk:
<input id="devicename" tpye="text" />
(state the device name)
<button onclick="registerDevice()">
Register the listener</button>
</div>
<span id="foundDevice"></span>
<div>
Data that has been received:
<span id="text">Waiting for data...</span>
</div>
</body>
</html>
|
2.2 Chrome based skins
The following script example is for the chrome-based skins of SiteKiosk.
The following line must be called to initialize the chrome version of the SiteKiosk Object Model:
<script>(new Function(_siteKiosk.getSiteKioskObjectModelCode()))();</script> |
This includes the required script functions. Then with the function
siteKiosk.devices.getAll a list of all devices registered in the SiteKiosk configuration can be loaded.
siteKiosk.devices.getAll() |
The function returns a JSON value with all devices.
To set up a listener for a single device the function
siteKiosk.devices.getByName can be used.
siteKiosk.devices.getByName(deviceName) |
deviceName = The name of the device in the SiteKiosk configuration (String)
The function returns an object that represents the respective device. Using the valueChanged function associated with this object the listener can be registered.
siteKiosk.devices.getByName(deviceName).valueChanged(callbackFunc) |
callbackFunc = Name of the function that is called after reading the data (String)
The
callbackFunc-Funktion has two parameters. The data that has been read as a string and also the name of the device from which the data was read.
Example:
The following example is an HTML page with a text box that is set up in the SiteKiosk configuration to activate the listener for a device name with a button click. It then reads data on the selected device which is displayed on the page. Please keep in mind that you need to give the URL that uses the SiteKiosk Object Model code
script permission under Access/Security.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Keyboard Emulation Device Test</title>
<script>(new Function(_siteKiosk.getSiteKioskObjectModelCode()))();</script>
<script>
var callbackFunc = function (data, deviceName) {
document.getElementById("text").innerHTML =
deviceName + " - " + data;
};
function GetDevices() {
var devices = siteKiosk.devices.getAll();
document.getElementById("devices").innerHTML =
JSON.stringify(devices);
}
function registerDevice() {
var deviceName = document.getElementById("devicename").
value;
if(deviceName == "")
return document.getElementById("foundDevice").
innerHTML = "No device found!";
var device = siteKiosk.devices.getByName(deviceName);
if(device == null)
return document.getElementById("foundDevice").
innerHTML = "No device found!";
device.valueChanged(callbackFunc);
return document.getElementById("foundDevice").
innerHTML = "Registered device: " +
JSON.stringify(device);
}
</script>
</head>
<body onload="GetDevices();">
<h1>Test page for reading the input of keyboard emulation
devices configured in the configuration of SiteKiosk</h1>
<div>Available devices:
<span id="devices"></span></div>
<div>
Listen to input from this device that has been
configured in SiteKiosk:
<input id="devicename" tpye="text" />
(state the device name) <button
onclick="registerDevice()">Register the
listener</button>
</div>
<span id="foundDevice"></span>
<div>Data that has been received: <span
id="text"></span></div>
</body>
</html>
|