Update: Connie Wiolowan of allanguages.info has made some comments and I've updated the post to reflect them. Thanks!
Connie also created a jQuery plugin for the virtual keyboard; see the comment for details.
I like Ilya Lebedev's JavaScript VirtualKeyboard a lot. It's clever, got an elegant UI, allows you to remap the physical keyboard to any language you want, and has an active and responsive support forum. But it's got a few quirks that make it hard to use with jQuery.
- Virtually no documentation. You have to read the source to get anywhere. But here's a brief introduction (assuming you use jQuery):
- Download the package from SourceForge, unzip the tarball and put the whole folder (don't mess up the organization!) somewhere accessible.
- Include the script with
<script type="text/javascript" src="/path/to/files/vk_loader.js" ></script>
. - Have a blank
<div>
in your HTML that will house the keyboard. I'll use<div id="jsvk" />
in these instructions. - Have one or more
<input type="text" >
s or<textarea>
s that will accept the keyboard input. - In your
$(document).load
function, include the statementVirtualKeyboard.show($('input')[0], $('#jsvk')[0])
. - Other useful functions include
VirtualKeyboard.hide()
that hides the keyboard and removes it from the DOM,VirtualKeyboard.attachInput($('input')[0])
that leaves the keyboard visible where it was but associates a new input element with it, andVirtualKeyboard.detachInput()
that leaves the keyboard visible but removes the association with an input element. VirtualKeyboard.open
is a synonym forVirtualKeyboard.show
andVirtualKeyboard.close
is a synonym forVirtualKeyboard.hide
.
- The
VirtualKeyboard
is a Singleton. This means that you can only have one keyboard shown on a page, and the "skin" (the CSS of the keyboard) is fixed at initialization even if you move it around and associate it with different input elements. It also means that if you use the keyboard for different input elements, changing the language for one changes it for all of them. You can get around this by putting the keyboard into its own document and using iframes or popup windows, and the code includes samples for both of those. - The package is huge. The "compacted" version is 4 MB. Most of that is the development files, so it's not like every page downloads megabyte files (the largest downloaded file is the keyboard layout package, about 390K), but it's still huge.
- Part of the reason that it's so big is that it does everything. Lebedev has put an entire Javascript library into this package, including its own event manager that overrides jQuery's. So you can't do
$('input').click(function(evt){})
on elements that are attached to the keyboard. You have to use hisEM.addEventListener(self.element[0],'click', function(evt){})
. - Options are too clever by half: he parses the
<script src="/path/to/vk_loader.js?query-string>
query string to get them. So to set the initial layout and the skin, I used<script type="text/javascript" src="/path/to/vk_loader.js?vk_layout=IL%20Hebrew&vk_skin=flat_gray" ></script>
. Options are:- vk_skin: name of folder in the /css folder in the package to use for the CSS
- vk_layout: name of the keyboard layout. The available names are listed on the right hand side of the home page or the project developement page
But these are really minor issues for such a great package, and adapting it to use jQuery isn't that hard (I'm using my textpopup
plugin as a base):
<div id="example">
Example: <br/><input style="float:left"/><input style="float:right"/>
<br style="clear:both"/>
</div>
var keyboard = false; // VirtualKeyboard is a singleton, so we have to make sure there's just one container
$.ui.textpopup.subclass("ui.jsvk", {
_createBox: function(){
if (keyboard) return keyboard;
var self=this;
self._super();
keyboard = self.theBox;
VirtualKeyboard.open(self.element[0], self.theBox[0]);
EM.addEventListener(self.element[0],'keypress', function(e){
if (e.getKeyCode()==27) self.hide();
});
return self.theBox;
},
show: function(){
VirtualKeyboard.attachInput(this.element[0]);
this._super();
},
hide: function(){
VirtualKeyboard.detachInput();
this._super();
}
});
$('#example input:eq(0)').jsvk({position: 'bl'});
$('#example input:eq(1)').jsvk({position: 'br'});