Freelancer's Playground! New knowledges every now and then

20Jun/100

Playing With Google’s Virtual Keyboard API

Several days ago I realize that google have been implementing it's virtual keyboard in google.co.id. I know that google already rolling it on several non English languages. I got curious as to wether we will be able to leverage this feature to our own site or not. I know that there are several open source library for this. But, let's stick with google API for now.

So, how do we start? Well, we obviously need to open our editor ;) . Next, create a html template.

<html>
	<head>
		<title>.: Testing Google Virtual Keyboard API :.</title>
	</head>
	<body>

	</body>
</html>

Then load google's jsapi into <head>

<script src="http://www.google.com/jsapi"></script>

After that, we need to load the appropriate package, that is keyboard

google.load("elements", "1", {packages: "keyboard"});

Before going too deep, we need to add text area.

<textarea name='textfield' value='' id='texttest' rows='11' cols='60'></textarea>

Now that we have the textarea, lets fill the code to actually load the virtual keyboard.

function onLoad() {
	var kbd = new google.elements.keyboard.Keyboard(
			[google.elements.keyboard.LayoutCode.ENGLISH],
			['texttest']);
}
google.setOnLoadCallback(onLoad);

You can test it here.