1

So I copied one of my small JavaScript games to my android phone and ran it in the browser. The game worked fine, except one fatal flaw: The game requires keyboard input, and it doesn't have a text field.

The game requires the user to type in certain letters, but they don't type it into a text field. I use a keydown event listener to get each key and process it accordingly.

So how do I invoke the android keyboard without having an actual text field?

1 Answer 1

3

Try this:

    <!DOCTYPE html>
<html>
<head lang="en">
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0, user-scalable=no"/>
    <style>
        *
        {
            padding :0;
            margin  :0;
        }
        html, body
        {
            width  :100%;
            height :100%;
        }
    </style>
</head>
<body>
    <div style="position: absolute;top:-1000px;left:-1000px">
        <input type="text" id="text">
    </div>
    <script>
        document.body.onclick=function()
        {
            console.log("here");
            var elem=document.getElementById("text");
            elem.focus()
        };
    </script>
</body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.