简体   繁体   中英

Samsung smart TV IME not focusing

When I tried to run my code, the whole screen was blur and when I pressed UP/DOWN key, the console showed IME input key skip and call event.preventDefault(), event.stopPropagation() .

Part of my codes:

HTML:

<body onLoad="func_onLoad()" onunload="func_onUnload()">
    <input id="username" type="text" onkeydown="onkeydown_input(this)" class="input username" placeholder="Username" required/>
    <input id="password" type="password" onkeydown="onkeydown_input(this)" class="input password" placeholder="Password" required/>
</body> 

ime.js:

var username = null;
var password = null;
var currentIMEObj = null;

function func_onLoad(){
alert("func_onLoad begin...");

username = new IMEShell_Common();
username.inputboxID = "username";
username.inputTitle = "username";
username.inputDescription = "Please enter your username";
username.onKeyPressFunc = onKeyCallback_username;
username.context = this;
username.setBlockSpace(true);

password = new IMEShell_Common();
password.inputboxID = "password";
password.inputTitle = "password";
password.inputDescription = "Please enter your password";
password.onKeyPressFunc = onKeyCallback_password;
password.context = this;
password.setBlockSpace(true);

document.getElementById("username").focus();
username.onShow();
}


function func_onUnload() {
alert("func_onUnload begin...");
if(username)
    username.onClose();
if(password)
    password.onClose();
}

function onkeydown_input(obj){
alert("onkeydown_input");
var EKC = event.keyCode;

switch(EKC){
    case(29460)://Up key
        if(obj.id == "username"){
            document.getElementById("username").blur();
            username.onClose();
        }
        else if(obj.id == "password"){
            document.getElementById("username").focus();
            username.onShow();
            currentIMEObj = username;
        }
    break;

    case(29461)://Down key
        if(obj.id == "username"){
            document.getElementById("password").focus();
            password.onShow();  
            currentIMEObj = password;
        }
        else if(obj.id == "password"){
            document.getElementById("password").blur();
            password.onClose();
        }
    break;

    case(29443)://Enter key
        if(obj.id == "username"){
            username.onShow();
            currentIMEObj = username;
        }
        else if(obj.id == "password"){
            password.onShow();
            currentIMEObj = password;
        }
    break;

    case(88)://return
    break;

    case(45)://exit   
        return;
    break;
}
}

function onKeyCallback_username(key,str,id) {
alert("CALLBACK onKeyCallback ===================: " + key + " ID = " + id + " STR = " + str);
switch (key) {
    case (29443): // Enter Key
        alert("ENTER");
        break;
    case (88):  //return
        alert("RETURN");
        break;
    case (45):  //exit
        alert("EXIT");
        break;
}
}


function onKeyCallback_password(key,str,id) {
alert("CALLBACK onKeyCallback ===================: " + key + " ID = " + id + " STR = " + str);
switch (key) {
    case (29443): // Enter Key
        alert("ENTER");
        break;
    case (88):  //return
        alert("RETURN");
        break;
    case (45):  //exit
        alert("EXIT");
        break;
}
}

Any one has any idea why username was not focused even though there was document.getElementById("username").focus(); in the func_onLoad() method and why event.preventDefault() was called.

Any help is appreciated!!! Thanks in advance!!!

Yes, we had similar problem in development. The issue arises if you handle the focus in the app independently. So if your app uses an independent framework to handle switching focus and active state, IME will not work as it will conflict with your own app's focus. The only solution is to create your own IME.

I don't no why the problem arises, but i think that andrea-f's answer is not quite right. Your code is OK. I know that because I had the same problem. I think that the problem is in the Emulator.

I have written very very similar code like yours, and i have had the same problem as yours (the same errors, the dimmed screen, etc.), but when i test the app on real device (my Samsung Smart F6400) it was working perfectly.

Try your app on a real device. That's my advice to you.

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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