In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

キーボードイベント確認用

Get Adobe Flash player
by ken_b4u 14 Dec 2010
/**
 * Copyright ken_b4u ( http://wonderfl.net/user/ken_b4u )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/rH4B
 */

package {
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    
    public class Typing extends Sprite
    {
        private var example:TextField;
        private var charCodeTf:TextField;
        private var keyCodeTf:TextField;
        private var shiftStateTf:TextField;
        private var ctrlStateTf:TextField;
        private var altStateTf:TextField;
                        
        public function Typing()
        {
            stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
            stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);            

            example = new TextField();
            example.text = "タイプしてください。";
            example.y = 0;
            addChild(example);

            charCodeTf = new TextField();
            charCodeTf.text = "キャラコード : ";
            charCodeTf.y = 40;
            addChild(charCodeTf);
            
            keyCodeTf = new TextField();
            keyCodeTf.text = "キーコード : ";
            keyCodeTf.y = 60;
            addChild(keyCodeTf);
            
            shiftStateTf = new TextField();
            shiftStateTf.text = "SHIFTキー : ";
            shiftStateTf.y = 80;
            addChild(shiftStateTf);
            
            ctrlStateTf = new TextField();
            ctrlStateTf.text = "CTRLキー : ";
            ctrlStateTf.y = 100;
            addChild(ctrlStateTf);
            
            altStateTf = new TextField();
            altStateTf.text = "ALTキー : ";
            altStateTf.y = 120;
            addChild(altStateTf);
        }
        
        private function onKeyDown(event:KeyboardEvent):void {
            charCodeTf.text = "キャラコード : " + event.charCode.toString();
            keyCodeTf.text = "キーコード : " + event.keyCode.toString();
            shiftStateTf.text = "SHIFTキー : " + event.shiftKey.toString();
            ctrlStateTf.text = "CTRLキー : " + event.ctrlKey.toString();
            altStateTf.text = "ALTキー : " + event.altKey.toString();
        }
        
        private function onKeyUp(event:KeyboardEvent):void {
            charCodeTf.text = "キャラコード : " + event.charCode.toString();
            keyCodeTf.text = "キーコード : " + event.keyCode.toString();
            shiftStateTf.text = "SHIFTキー : " + event.shiftKey.toString();
            ctrlStateTf.text = "CTRLキー : " + event.ctrlKey.toString();
            altStateTf.text = "ALTキー : " + event.altKey.toString();
        }
    }
}