locked
key event does not response to virtual keyboard in metro app

    Question

  • Hi , 

    I am testing the code below in touchable screen in metro app on win8 system, but I found the virtual keyboard is not response to the onkeydown event...

    html:

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title>VirtualKeyboardKeyEventTest</title>
    
        <!-- WinJS references -->
        <link href="//Microsoft.WinJS.0.6/css/ui-dark.css" rel="stylesheet">
        <script src="//Microsoft.WinJS.0.6/js/base.js"></script>
        <script src="//Microsoft.WinJS.0.6/js/ui.js"></script>
    
        <!-- VirtualKeyboardKeyEventTest references -->
        <link href="/css/default.css" rel="stylesheet">
        <script src="/js/default.js"></script>
    </head>
    <body>
        <textarea id="ta"></textarea>
        <p id="output"></p>
    </body>
    </html>
    

    js:

    // For an introduction to the Blank template, see the following documentation:
    // http://go.microsoft.com/fwlink/?LinkId=232509
    (function () {
        "use strict";
    
        var app = WinJS.Application;
    
        var id = function (ele) {
            return document.getElementById(ele);
        };
    
        app.onactivated = function (eventObject) {
            if (eventObject.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
                if (eventObject.detail.previousExecutionState !== Windows.ApplicationModel.Activation.ApplicationExecutionState.terminated) {
                    // TODO: This application has been newly launched. Initialize 
                    
                    var ta = id('ta');
    
                    ta.onkeydown = function () {
                        id('output').innerHTML = 'key down...';
                    };
                    ta.onkeyup = function () {
                        id('output').innerHTML = 'key up...';
                    };
    
                } else {
                    // TODO: This application has been reactivated from suspension. 
                    // Restore application state here.
                }
                WinJS.UI.processAll();
            }
        };
    
        app.oncheckpoint = function (eventObject) {
            // TODO: This application is about to be suspended. Save any state
            // that needs to persist across suspensions here. You might use the 
            // WinJS.Application.sessionState object, which is automatically
            // saved and restored across suspension. If you need to complete an
            // asynchronous operation before your application is suspended, call
            // eventObject.setPromise(). 
        };
    
        app.start();
    })();
    

    Any suggestion for raising key event by virtual keyboard in win 8?

    Thanks!


    sun

    Thursday, April 5, 2012 9:25 AM

Answers

  • Your sample code is working fine for me.
    Are you using the On-Screen keyboard that came with Windows?

    It is also possible you are overwriting the output for keydown with the output from keyup event. Try changing your debug statements to append instead of overwriting (ex:  id('output').innerHTML += 'key down...';)  or use console.log.

    Yes, I am using the on-screen keyboard that came with windows 8 b.8250.

    After test with (id('output').innerHTML += 'key down...';) I found that it works fine in English input method, but in Chinese input method, it does not raise any key event.



    sun

    • Marked as answer by Bin.Sun Monday, September 17, 2012 3:30 AM
    Monday, April 9, 2012 2:50 AM

All replies

  • Your sample code is working fine for me.
    Are you using the On-Screen keyboard that came with Windows?

    It is also possible you are overwriting the output for keydown with the output from keyup event. Try changing your debug statements to append instead of overwriting (ex:  id('output').innerHTML += 'key down...';)  or use console.log.

    Friday, April 6, 2012 4:22 PM
  • Your sample code is working fine for me.
    Are you using the On-Screen keyboard that came with Windows?

    It is also possible you are overwriting the output for keydown with the output from keyup event. Try changing your debug statements to append instead of overwriting (ex:  id('output').innerHTML += 'key down...';)  or use console.log.

    Yes, I am using the on-screen keyboard that came with windows 8 b.8250.

    After test with (id('output').innerHTML += 'key down...';) I found that it works fine in English input method, but in Chinese input method, it does not raise any key event.



    sun

    • Marked as answer by Bin.Sun Monday, September 17, 2012 3:30 AM
    Monday, April 9, 2012 2:50 AM