Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Capture keyCode on keyDown

    Hi

    I need to obtain the "keyCode"/"charCode" of a TextItem when keyDown.

    isc.Event.getKey() doesn't fit my requirements since for example the . (dot) of the keyboard is different from the . (dot) of the numeric keyboard and I need to distinguish between them.

    Any idea?

    Thanks.

    David.

    #2
    The value you want is part of keyPress event if you can handle it there instead. Be sure to call the Super if you don't handle the event fully.

    Comment


      #3
      Thanks davidj6, I would prefer keyDown, but I will try with keyPress.

      The problem is that I don't know exactly how to implement it.

      In the following mini-example which should exactly go instead of the XXXXXX to obtain the keyCode in the keyCodeVariable?

      isc.DynamicForm.create({
      fields: [{
      type: "TextItem",
      keyPress: function () {
      var keyCodeVariable = XXXXXX;
      console.log(keyCodeVariable);
      }]
      });

      Comment


        #4
        See the keyPress docs for full details. But in general you need something like:
        Code:
        keyPress: function (item, form, keyName, characterValue) { 
          var keyCodeVariable = characterValue;
          console.log(keyCodeVariable);
        
          this.Super("keyPress", arguments);
        }

        Comment


          #5
          Thanks, I have tested, but I have obtained which I fear

          by keyPress the . (dot) from the keyboard and the numeric keyboard is the same (charCode = 46)

          by keyDown (in standard Javascript: (evt.keyCode))

          the keyCode of the . (dot) in the keyboard is 190 and in numeric keyboard 110

          I need the keyCode captured by keyDown which has different values for the different dots....

          Is there any way to capture it?

          Comment


            #6
            Could davidj6 or anybody tell me if it is possible to obtain the keyDown keyCode of a TextItem or should I start to think other options?

            Thanks in advance

            Comment


              #7
              It appears that the browser is not giving the actual keyCode. In my testing in a couple of browsers (not IE) I was unable to obtain the keyCode in question. The keyCode reported in the event is part of the keyPress as noted previously but it may not be accurate...

              Comment


                #8
                davidj6

                Here (at the end) is a basic example of how keyCode works onKeyDown. This example works in FF, IE and Chrome.

                You could see that the . (dot) of the numeric keyboard and the standard keyboard returns different keyCodes.

                My point is if it would be possible to obtain the keyCode onKeyDown on a SmartClient TextItem...

                Please forget KeyPress since it returns different keycode/charcode than keyDown (and I need keyDown ones).

                Code:
                <html>
                  <head>
                    <script type="text/javascript">
                       function getKeyCode(event) {
                           if (!event) event = window.event;
                           var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
                           alert(keyCode);
                       }
                    </script>
                  </head>
                  <body>
                    <input type="text" onkeydown="getKeyCode(event);"></input>
                  </body>
                </html>

                Comment


                  #9
                  The keyCode is only recorded at present during the keypress event and therefore it has the translated code, not the original keydown keyCode. I do not know the reason for not recording the keyCode in the keydown handler at present.

                  If this is important to you (which it seems to be), add your request to the wish list.

                  Comment


                    #10
                    I have been playing around and...

                    in file EventHandler.js

                    if we add, for example after "getKey: function (event)...", this new function:

                    Code:
                    getKeyCode : function (event) {
                        return (event || this.lastEvent).nativeKeyCode;
                    },
                    Then I am able to do this inside my TextItem declaration

                    Code:
                      keyDown: function () { 
                        var capturedKeyCode = isc.EventHandler.getKeyCode();
                        console.log("The pressed key code: " + capturedKeyCode);
                      }
                    So my question is... could any developer (if he agrees) include my provided getKeyCode function inside EventHandler.js in the Smartclient source code in order to have it ready in a future daily build to avoid editing it by myself each time I update sources?

                    Thanks.

                    Comment


                      #11
                      We're already looking at a similar enhancement, just want to be sure we're doc'ing on what browsers and during what events the keyCode is reliable.

                      Comment


                        #12
                        I plan to make an upgrade to the latest nightly build, but I see that still this topic is not managed.

                        I added manually this line
                        ,isc.A.getKeyCode=function(_1){return(_1||this.lastEvent).nativeKeyCode}

                        after the line
                        ,isc.A.getKey=function(_1){return(_1||this.lastEvent).keyName}

                        inside ISC_Core.js

                        Have you planned to add (or something similar) in your code repositories?

                        Regards

                        Comment

                        Working...
                        X