5 Replies Latest reply: May 3, 2012 6:35 PM by zyhsu RSS

    javascript, text input


      Dear sir:


      If I want to getTextString directly from keyboard input, not from textfield,

      Can I do that?


        • 1. Re: javascript, text input
          Ned Murphy MVP

          You would need to store the characters that are being typed into a String variable. So you need to capture which keys are being used and add the characters for them to the string.

          • 2. Re: javascript, text input
            sinious MVP

            Is this input inside Flash or just a standard HTML <input type="text" ..> situation?

            • 3. Re: javascript, text input

              Dear Ned:


              Thanks for your reply!


              So, It will not like we use "scanf" in  C ,  we can have the program hold, wait for our input,

              then tab return, the function will scan what we input and take it as variable?





              • 4. Re: javascript, text input
                Ned Murphy MVP

                I cannot speak for what you do in C.  What you do in Actionscript depends on what version you are using, but for any version it boils down to having a listener assigned for keyboard input when you want keyboard input to be monitored.  In AS3 you would assign a listener for a KeyboardEvent and then have the event handler function determine which key was used and add it to the string.  Here is a very basic implementation to demonstrate (be sure to disable keyboard shortcuts in the player when you test it in Flash using Control -> Disable Keyboard Shortcuts).



                var str:String = "";


                stage.addEventListener(KeyboardEvent.KEY_UP, keyUsed);


                function keyUsed(evt:KeyboardEvent){
                     str += String.fromCharCode(evt.charCode);

                • 5. Re: javascript, text input

                  Dear Ned:


                  Thanks a lot! this exatly I am looking for!

                  Ze-Yi Hsu