Skip navigation
Currently Being Moderated

javascript, text input

May 3, 2012 12:18 AM

Dear sir:

 

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

Can I do that?

thanks!

 
Replies
  • Currently Being Moderated
    May 3, 2012 5:06 AM   in reply to zyhsu

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    May 3, 2012 6:04 AM   in reply to Ned Murphy

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

     
    |
    Mark as:
  • Currently Being Moderated
    May 3, 2012 4:50 PM   in reply to zyhsu

    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);
         trace(str);
    }

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points