Import KioskBoard
mainIn a module-based environment (like React or modern JS), import the KioskBoard object to access its API.
import KioskBoard from 'kioskboard';repository·main·Indexed 18 days ago
https://github.com/furcan/kioskboardA pure JavaScript library for providing virtual keyboards in web applications, specifically designed for kiosk environments and touch-based interfaces. It supports customizable layouts via JSON or JavaScript objects, multiple visual themes, and configurable keyboard types including full keyboards and numpads. Version 2.3.0 features include automatic scrolling to focused inputs, mobile keyboard suppression, and configuration via HTML data attributes.
In a module-based environment (like React or modern JS), import the KioskBoard object to access its API.
import KioskBoard from 'kioskboard';You can install KioskBoard using npm or yarn to use it in your JavaScript/TypeScript projects.
# Using npm
npm i kioskboard
# Using yarn
yarn add kioskboardIf you are not using a module bundler, you can include KioskBoard directly in your HTML. You have two options:
<!-- Option 1: CSS and JS -->
<link rel="stylesheet" href="dist/kioskboard-2.3.0.min.css" />
<script src="dist/kioskboard-2.3.0.min.js"></script>
<!-- Option 2: All in One (Internal CSS) -->
<script src="dist/kioskboard-aio-2.3.0.min.js"></script>You can configure individual input or textarea elements using data-* attributes. This allows different elements to have different keyboard behaviors.
Supported attributes:
data-kioskboard-type: Keyboard type (all, keyboard, or numpad). Default is all.data-kioskboard-placement: Keyboard position (top or bottom). Default is bottom.data-kioskboard-specialcharacters: Whether to show special characters (true or false).Example usage:
<!-- Textarea: all type, top placement, special characters enabled -->
<textarea class="js-virtual-keyboard" data-kioskboard-type="all" data-kioskboard-placement="top" data-kioskboard-specialcharacters="true" placeholder="Your Address"></textarea>
<!-- Input: keyboard type, bottom placement, special characters disabled -->
<input class="js-virtual-keyboard" data-kioskboard-type="keyboard" data-kioskboard-placement="bottom" data-kioskboard-specialcharacters="false" placeholder="Your Name" />
<!-- Input: numpad type, bottom placement (special characters are not allowed for numpad) -->
<input class="js-virtual-keyboard" data-kioskboard-type="numpad" data-kioskboard-placement="bottom" placeholder="Your Number" />KioskBoard manages the relationship between the virtual keyboard and HTML input elements through several automated behaviors:
<style id="KioskboardBodyPadding"> element into the <head> and add a .kioskboard-body-padding class to the <body>. This adds padding to the top or bottom of the document to accommodate the keyboard height.allowMobileKeyboard is set to false, the library manages the readonly attribute of inputs during focus/blur cycles to prevent the native mobile keyboard from appearing simultaneously with the KioskBoard.KioskBoard can be initialized and run using two main patterns in JavaScript.
Use KioskBoard.run(selector, options) to immediately target elements matching a CSS selector and apply configuration.
KioskBoard.run('.js-virtual-keyboard', {
// ...init options
});Use KioskBoard.init(options) to set global configurations first, then use KioskBoard.run(selector) to activate it on specific elements.
// Step 1: Initialize with global settings
KioskBoard.init({
keysArrayOfObjects: [...],
theme: 'light',
// ...other options
});
// Step 2: Run on specific elements
KioskBoard.run('.js-virtual-keyboard');KioskBoard.run('.js-virtual-keyboard', { /* options */ });
// OR
KioskBoard.init({ /* options */ });
KioskBoard.run('.js-virtual-keyboard');When initializing KioskBoard, you can control what happens when the 'Enter' key is pressed on the virtual keyboard using the following options:
keysEnterCanClose: If set to true, clicking the Enter key will automatically remove (close) the virtual keyboard.keysEnterCallback: A function that is executed when the Enter key is clicked. This is useful for triggering form submissions or other logic.// Example configuration
KioskBoard({
keysEnterCanClose: true,
keysEnterCallback: function() {
console.log('Enter key pressed!');
}
});KioskBoard can automatically scroll the window to ensure the focused input remains visible when the keyboard appears. Use these options to control it:
autoScroll: Set to true to enable automatic scrolling.cssAnimations: Set to true to use smooth scrolling behavior instead of auto (instant).cssAnimationsDuration: A number representing the duration of the scroll animation (used when cssAnimations is true).KioskBoard({
autoScroll: true,
cssAnimations: true,
cssAnimationsDuration: 300
});Instead of providing keys directly in the configuration, you can instruct KioskBoard to fetch keyboard layouts from a remote JSON file using the keysJsonUrl option.
KioskBoard uses XMLHttpRequest to fetch the data. The fetched JSON must be an array of objects representing the keys. The library caches these keys internally to avoid redundant network requests if multiple inputs are used.
KioskBoard({
keysJsonUrl: 'https://example.com/path/to/keyboard-layout.json'
});If you use the keysJsonUrl option, your JSON file must follow a specific structure where each object in the array represents a row on the keyboard. The keys in the object act as indices, and the values are the text displayed on the keys.
Example JSON structure:
[
{
"0": "Q",
"1": "W",
"2": "E"
},
{
"0": "A",
"1": "S",
"2": "D"
}
][
{
"0": "Q",
"1": "W",
"2": "E",
"3": "R",
"4": "T",
"5": "Y",
"6": "U",
"7": "I",
"8": "O",
"9": "P"
},
{
"0": "A",
"1": "S",
"2": "D",
"3": "F",
"4": "G",
"5": "H",
"6": "J",
"7": "K",
"8": "L"
},
{
"0": "Z",
"1": "X",
"2": "C",
"3": "V",
"4": "B",
"5": "N",
"6": "M"
}
]When calling KioskBoard.init() or KioskBoard.run(), you can pass an options object to customize the keyboard behavior.
One of the following must be provided to define the keyboard layout:
keysArrayOfObjects: An array of objects where each object represents a row. Example: [{"0":"A","1":"B"}, {"0":"C","1":"D"}].keysJsonUrl: A string path to a JSON file containing the keys (used via XMLHttpRequest). The JSON format must match the keysArrayOfObjects structure.language: ISO 639-1 language code (e.g., 'en', 'de', 'fr').theme: 'light', 'dark', 'flat', 'material', or 'oldschool'.keysSpecialCharsArrayOfStrings: Array of strings to override built-in special characters.keysNumpadArrayOfNumbers: Array of numbers (0-9) to override numpad keys.keysSpacebarText: Text for the space key (defaults to ' ').keysEnterText: Text for the Enter key.keysEnterCallback: Function called when the Enter key is clicked.keysEnterCanClose: Boolean; if false, the Enter key won't close the keyboard.cssAnimations: Boolean to enable/disable animations.cssAnimationsStyle: 'slide' or 'fade'.cssAnimationsDuration: Duration in milliseconds.keysFontFamily: CSS font family string.keysFontSize: CSS font size string (e.g., '22px').keysFontWeight: CSS font weight string.keysIconSize: CSS icon size string.autoScroll: Boolean; scrolls the document to the input element's position.capsLockActive: Boolean; starts the keyboard in uppercase if true.allowRealKeyboard: Boolean; allows/prevents physical keyboard usage.allowMobileKeyboard: Boolean; allows/prevents mobile system keyboard usage.keysAllowSpacebar: Boolean; enables/disables spacebar functionality.KioskBoard.init({
keysArrayOfObjects: null, // or keysJsonUrl
language: 'en',
theme: 'light',
autoScroll: true,
capsLockActive: true,
allowRealKeyboard: false,
allowMobileKeyboard: false,
cssAnimations: true,
cssAnimationsDuration: 360,
cssAnimationsStyle: 'slide',
keysAllowSpacebar: true,
keysSpacebarText: 'Space',
keysFontFamily: 'sans-serif',
keysFontSize: '22px',
keysFontWeight: 'normal',
keysIconSize: '25px',
keysEnterText: 'Enter',
keysEnterCallback: undefined,
keysEnterCanClose: true,
});To attach the virtual keyboard to an input or textarea, use KioskBoard.run(selectorOrElement, options).
selectorOrElement can be:
HTMLInputElement or HTMLTextAreaElement.'#my-input').options (optional) allows you to override or extend the global configuration specifically for this instance.
Keyboard Types via Data Attributes:
You can control the keyboard type and placement for specific inputs using data-* attributes on the HTML element:
data-kioskboard-type: Set to 'all', 'keyboard', or 'numpad'.data-kioskboard-placement: Set to 'top' or 'bottom'.data-kioskboard-specialcharacters: Set to 'true' to enable the special characters button.// Using a selector
KioskBoard.run('#my-input');
// Using a direct element with specific overrides
const myInput = document.querySelector('input');
KioskBoard.run(myInput, {
theme: 'material'
});