simple-keyboard

Modules

Modules for simple-keyboard enrich your virtual keyboard experience. Check out a list of some of the plugins available so far:

How do modules work?

Modules are essentially Javascript classes that attach to an instance of simple keyboard at run-time. These plugins are able to access simple-keyboard variables and methods, modify standard behavior, leverage new options and more.

How to create my own module?

Creating your own module is easy. Just create a Javascript class incorporating an init method. Check out this example:

class MyModule {
  init = (keyboard) => {

    /**
     * Registering module
     */
    keyboard.registerModule(
      "myModule",
      (module) => {

        /**
         * Creating a method
         */
        module.myMethod = () => {
          console.log(keyboard.getInput());
        }

        module.myMethod();
      }
    );
  }
}

export default MyModule;

This code basically creates a function “myMethod” under “keyboard.modules.myModule” and fires it. This namespacing helps avoid name-clashing and accidental overrides.

How to add my module to Simple Keyboard?

To attach your module to a given virtual keyboard instance, use the “module” option:

npm

import Keyboard from 'simple-keyboard';
import MyModule from 'my-module';

let keyboard = new Keyboard({
  onChange: input => onChange(input),
  onKeyPress: button => onKeyPress(button),
  modules: [
    MyModule
  ]
});

cdn

let Keyboard = window.SimpleKeyboard.default;
let MyModule = window.MyModule.default;

let keyboard = new Keyboard({
  onChange: input => onChange(input),
  onKeyPress: button => onKeyPress(button),
  modules: [
    MyModule
  ]
});

You’ve made a neat module for simple-keyboard? Let us know so we can include it to this page :
https://github.com/hodgef/simple-keyboard/issues