Handling TV Remote Key Events in Samsung Smart TV

When developing applications for Samsung Smart TV, one of the most important area to focus is user interactivity. The applications become more lively when the user interacts with it like entering data, selecting a menu or option etc. Samsung Smart TV provides various methods of user interaction like TV Remote, WiFi Connectivity, Gesture Recognition, Voice Recognition etc. These methods of user interaction are found scattered over various models of Smart TV. Among these features, the one that is most commonly used and the one that is available with every TV model is the TV Remote. Hence the ability to handle a TV Remote Key event, has been considered one of the features of an interactive application. Even the application is not that interactive, the TV Remote Key Event management is needed at some basic levels like volume control, closing the application, minimizing the application, channel access etc. So this article will be about how to handle the TV Remote key events by program.

As soon as we open a basic JavaScript application in a Samsung Smart TV SDK, the project created will include two JavaScript files by default. They are as follows

<script src="$MANAGER_WIDGET/Common/API/Widget.js"></script>
<script src="$MANAGER_WIDGET/Common/API/TVKeyValue.js"></script>

The first file has the basic application framework functions like Application Manager, firing up the necessary starup up events etc. The Second file contains the definitions for the TV Remote Key Events. The basic principle of TV Remote Handling is that, each key is associated with a standardized code. Once the key is pressed, it is associated with a Key Press Handler, that receives the standardized key code. This will be compared to find out the key that is triggered and the corresponding action will be taken. For handling key events, the key has to be registered first with an event handler. The following are the standardized key codes for Samsung Smart TV.

KEY_TOOLS: 75,
KEY_MUTE: 27,
KEY_RETURN: 88,
KEY_UP: 29460,
KEY_DOWN: 29461,
KEY_LEFT: 4,
KEY_RIGHT: 5,
KEY_WHEELDOWN: 29469,
KEY_WHEELUP: 29468,
KEY_ENTER: 29443,
KEY_INFO: 31,
KEY_EXIT: 45,
KEY_RED: 108,
KEY_GREEN: 20,
KEY_YELLOW: 21,
KEY_BLUE: 22,
KEY_INFOLINK: 147,
KEY_RW: 69,
KEY_PAUSE: 74,
KEY_FF: 72,
KEY_PLAY: 71,
KEY_STOP: 70,
KEY_1: 101,
KEY_2: 98,
KEY_3: 6,
KEY_4: 8,
KEY_5: 9,
KEY_6: 10,
KEY_7: 12,
KEY_8: 13,
KEY_9: 14,
KEY_0: 17,
KEY_EMPTY: 0,
KEY_PRECH: 259,
KEY_SOURCE: 222,
KEY_CHLIST: 84,
KEY_MENU: 262,
KEY_WLINK: 115,
KEY_CC: 118,
KEY_CONTENT: 261,
KEY_FAVCH: 256,
KEY_REC: 192,
KEY_EMODE: 148,
KEY_DMA: 260,
KEY_PANEL_CH_UP: 104,
KEY_PANEL_CH_DOWN: 106,
KEY_PANEL_VOL_UP: 203,
KEY_PANEL_VOL_DOWN: 204,
KEY_PANEL_ENTER: 309,
KEY_PANEL_SOURCE: 612,
KEY_PANEL_MENU: 613,
KEY_PANEL_POWER: 614,
KEY_POWER: 76,
KEY_TV: 77,
KEY_VOL_UP: 7,
KEY_VOL_DOWN: 11,
KEY_CH_UP: 68,
KEY_CH_DOWN: 65,
KEY_TTX_MIX: 650,
KEY_GUIDE: 651,
KEY_SUBTITLE: 652,
KEY_ASPECT: 653,
KEY_DOLBY_SRR: 654,
KEY_MTS: 655,
KEY_12: 1057,
KEY_DISC_MENU: 1086,
KEY_3D: 1219,
KEY_PIP_ONOFF: 1032,
KEY_AD: 1039,
KEY_PMODE: 1040,
KEY_SMODE: 1043,
KEY_PIP_CHUP: 1050,
KEY_PIP_CHDOWN: 1051,
KEY_FF_: 1078,
KEY_REWIND_: 1080,
KEY_SUB_TITLE: 1089,
KEY_SLEEP: 1097,
KEY_D_AUDIO: 1236,
KEY_D_FRONT_PLAY: 1243,
KEY_D_VIEW_MODE: 1249,
KEY_STEP: 1023,
KEY_CALLER_ID: 1128,
KEY_ZOOM1: 1083,
KEY_ANTENA: 1054,
KEY_DVR: 1114,
KEY_HOME: 1118,
KEY_TV_SNS: 1251,
KEY_SEARCH: 1252,
KEY_VTUNER: 1049,
KEY_NETFLIX: 1052,
KEY_HDMI: 1139,
KEY_DOTCOM: 1253,
KEY_PANDORA: 124,
KEY_DIGITAL_LOCKER: 137,
KEY_EMANUAL: 63,
KEY_BT_NUMBER: 247,
KEY_BT_HOTKEY: 248,
KEY_PAGEMODE: 30000030,
QWERTY_KEY_1: 10000101,
QWERTY_KEY_2: 10000098,
QWERTY_KEY_3: 10000006,
QWERTY_KEY_4: 10000008,
QWERTY_KEY_5: 10000009,
QWERTY_KEY_6: 10000010,
QWERTY_KEY_7: 10000012,
QWERTY_KEY_8: 10000013,
QWERTY_KEY_9: 10000014,
QWERTY_KEY_0: 10000017,
KEY_GESTURE_UP: 40000002,
KEY_GESTURE_DOWN: 40000003,
KEY_GESTURE_LEFT: 40000004,
KEY_GESTURE_RIGHT: 40000005,
KEY_PAD_1: 50000101,
KEY_PAD_2: 50000098,
KEY_PAD_3: 50000006,
KEY_PAD_4: 50000008,
KEY_PAD_5: 50000009,
KEY_PAD_6: 50000010,
KEY_PAD_7: 50000012,
KEY_PAD_8: 50000013,
KEY_PAD_9: 50000014,
KEY_PAD_0: 50000017



Once the key code is obtained, it is compared with the corresponding key by looking at this table for identification. By including the TVKeyValue library file, it provides an utility object to check the key code during the event of a key press. The utility object is

window.TvKeyCode

So for example, if I need to check whether the detected key event is from key pad 1, I will be doing the following to detect it.

if(window.TvKeyCode.KEY_PAD_1 === received_key_code) {
//take necessary action
}

Without the utility object, we may have to manually compare the key code with the above list, will be a bit tedious process. In order to avoid this, Samsung Smart TV SDK includes, the utility object by default. So hence by default, the Smart TV SDK is providing provisions for handling TV Remote key events, which is one of the basic modes of interaction with the TV. Further user interaction handling includes voice control, gesture control, WiFi and Bluetooth etc, will be covered in further tutorials.




No Comments


You can leave the first : )



Leave a Reply

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