Virtual Keyboard Playground

https://github.com/Mottie/Keyboard

by Mottie

HTML

<link rel="stylesheet" href="https://mottie.github.io/Keyboard/css/keyboard.css">
<script src="https://mottie.github.io/Keyboard/js/jquery.keyboard.js"></script>
<script src="https://mottie.github.io/Keyboard/js/jquery.mousewheel.js"></script>
<script src="https://mottie.github.io/Keyboard/js/jquery.keyboard.extension-typing.js"></script>
<script src="https://mottie.github.io/Keyboard/js/jquery.keyboard.extension-autocomplete.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/ui-lightness/jquery-ui.css">
<script src="https://mottie.github.io/Keyboard/docs/js/jquery-ui.min.js"></script>
<div id="wrap">
  <input type="text" class="keyboard-init-focus" />
  <input type="text" />
  <input type="text" class="last" />
</div>

CSS

input {
  width: 40px;
}

body {
  margin-top: 100px;
}

#wrap {
  display: block;
  margin: 0 auto;
  width: 250px;
  height: 40px;
}

JavaScript

$(function() {
  $("input").keyboard({
    position: {
      // position under center input
      of: $("input:eq(1)"),
      // move down 12px; not sure why it doesn't line up
      my: 'center top+12',
      at: 'center top'
    },
    enterNavigation: true,
    maxLength: 4,
    layout: 'num',
    initialFocus: false,
    autoAccept: true,
    usePreview: false,
    change: function(e, keyboard, el) {
      var len = keyboard.$el.hasClass("last") ? 4 : 3,
        key = keyboard.last.keyPress;
      // don't switch if user pressed arrow keys
      if (
        keyboard.$el.val().length >= len &&
        !( key === 37 || key === 39 )
      ) {
        // switchInput( goToNext, isAccepted );
        keyboard.switchInput(true, true);
      } else if (keyboard.$el.val() === "" && keyboard.last.key === "bksp") {
        // go to previous if user hits backspace on an empty input
        keyboard.switchInput(false, true);
      }
    }
  });
});