简体   繁体   English

如何在tizen中执行默认键操作?

[英]how to perform default key operations in tizen?

I am trying to develop a basic Tizen tv application.我正在尝试开发一个基本的 Tizen 电视应用程序。 for that, I've created two anchor tags and a button.为此,我创建了两个锚标记和一个按钮。 the code is as follows.代码如下。

  <!DOCTYPE html>
<html>
<head>
    <title>ReactSampleApp</title>
    <style>
    body,html{
        position:absolute;
        padding:0px;
        margin:0px;
        width:100%;
        height:100%;
        background:#fff;
    }
</style>
<script src="js/main.js"></script>
</head>

<body> 
    <a href="./page2.html">
    <button>click here for some music</button>
    </a>
    <a href="./page3.html">
    <button>click here to go to page3</button>
    </a>
    <button onclick="function(){alert(0)}">click here for an alert</button>
    
</body>
</html>

as you can see it's just a normal sample HTML page that traverses to different pages upon these button clicks.如您所见,它只是一个普通的示例 HTML 页面,在单击这些按钮时会遍历到不同的页面。

and it works fine, so no problems there.它工作正常,所以没有问题。

the problem lies while focusing on the elements.问题在于关注要素。 well, it's not exactly a problem just my doubt.好吧,这不完全是我的疑问。

window.onload = function() {

    // add eventListener for keydown
    document.addEventListener('keydown', function(e) {
        switch(e.keyCode){
        case 37: //LEFT arrow
            break;
        case 38: //UP arrow
            break;
        case 39: //RIGHT arrow
            break;
        case 40: //DOWN arrow
            break;
        case 13: //OK button
//          window.open("/page2.html");
            break;
        case 10009:
            tizen.application.getCurrentApplication().exit();
            break;
        default:
            console.log('Key code : ' + e.keyCode);
            break;
        }
    });
    
};

this code is from my main.js file.这段代码来自我的 main.js 文件。

I just wrote it to handle the key events - up, down, left, right, and enter.我只是写它来处理关键事件 - 向上、向下、向左、向右和输入。 now inside this switch block, I was able to write alerts and was able to interact with the page.现在在这个 switch 块中,我能够编写警报并能够与页面交互。 but now instead of alerts I want to give regular up, down, left, right, enter inputs.但现在,我想定期向上、向下、向左、向右输入输入,而不是警报。

meaning - say if there was a grid(a dynamic one).意思 - 说是否有一个网格(一个动态的)。 How do I focus on elements by traversing them horizontally or vertically?如何通过水平或垂直遍历元素来关注元素? do I need to write explicit code or am I missing something here?我需要编写明确的代码还是我在这里遗漏了什么? does Tizen provide this basic traversal of web elements with input keys? Tizen 是否提供这种带有输入键的 Web 元素的基本遍历?

Thanks in advance提前致谢

For remote control key events to be passed through to the JS runtime of your client app you first need to register the key events that you want to use with the registerKey method要将远程控制键事件传递到客户端应用程序的 JS 运行时,您首先需要使用registerKey方法registerKey要使用的键事件

https://www.tizen.org/tv/web_device_api/tvinputdevice#::TVInputDevice::TVInputDeviceManager::registerKey https://www.tizen.org/tv/web_device_api/tvinputdevice#::TVInputDevice::TVInputDeviceManager::registerKey

Use the value from the "Key Name" column in the table at the bottom of this page: https://developer.samsung.com/smarttv/develop/guides/user-interaction/remote-control.html使用本页底部表格中“密钥名称”列中的值: https : //developer.samsung.com/smarttv/develop/guides/user-interaction/remote-control.html

For example to register the "red" button on the TV remote control..例如注册电视遥控器上的“红色”按钮..

window.tizen.tvinputdevice.registerKey("ColorF0Red");

Then you can listen for a keycode value of 403 in your keyDown handler然后您可以在 keyDown 处理程序中监听 403 的键码值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM