Default Remote Key handling setup in Samsung Smart TV

Samsung Smart TV
2 minutes read

The project wizard in Samsung smart TV helps the developer to bootstrap a project with almost no basic setup. All the project types have an associated project wizard for bootstrapping. The bootstrapped applications will have the basic configurations setup enabled by default. One among those default setup is the default remote key handling. This article explains the default remote key handling setup in the case of a Samsung smart TV basic JavaScript application.

Intelligent defaults

Almost all the bootstrapped Samsung smart TV projects will have the defaults set up automatically. The intelligent defaults will even further speed up the development process. In the case of a default JS TV application, the default remote key handling is setup automatically.



Remote key handling

TV remote is the most used method of interaction with the TV. Remote key handling in TV involves triggering actions when the remote key is pressed. The pressed key is identified by means of an unique key code. The unique key code remains the same, no matter the type of the smart TV remote used. Most of the basic keys like enter, directional keys, number keys etc are handled by default.

Code walk-through

The default remote key handler code will print out the currently pressed key name to the console. The developer has to modify the handler code and replace it with custom logic. The following code block illustrates the handling logic

Main.keyDown = function() {
	var keyCode = event.keyCode;
	alert("Key pressed: " + keyCode);

	switch (keyCode) {
	case tvKey.KEY_RETURN:
	case tvKey.KEY_PANEL_RETURN:
		alert("RETURN");
		widgetAPI.sendReturnEvent();
		break;
	case tvKey.KEY_LEFT:
		alert("LEFT");
		break;
	case tvKey.KEY_RIGHT:
		alert("RIGHT");
		break;
	case tvKey.KEY_UP:
		alert("UP");
		break;
	case tvKey.KEY_DOWN:
		alert("DOWN");
		break;
	case tvKey.KEY_ENTER:
	case tvKey.KEY_PANEL_ENTER:
		alert("ENTER");
		window.location.href="demo.html";
		break;
	default:
		alert("Unhandled key");
		break;
	}
};




Each case involves checking the pressed key by using the key code. The list of key codes can be viewed from one of my previous posts. The developer has to include custom logic for keys that needs to be handled. The above handler code is triggered from a keypress action on a hyperlink attached to the landing page. This can be seen from the codeblock below
<a href="javascript:void(0);" id="anchor" onkeydown="Main.keyDown();"></a>

The above code snippet shows the process of attaching a keypress event on a hyperlink. The developer just has to start developing the business logic. There is no need for manually bootstrapping the app and attaching remote key event handlers

Advantages of intelligent defaults

Intelligent defaults provide various common features setup by default. The developer can start developing on the business logic without concentrating on the basic setup. The default remote key handling feature will save the developer a lot of coding . The TV remote being the main mode of interaction with the TV. This article has explored the default setup of key events in smart TV basic JavaScript application. Each application type will be having it’s own kind of defaults. Please do comment the default setup for other projects.




No Comments


You can leave the first : )



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.