A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [MX04] Using other Keysboard buttons

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    49

    [MX04] Using other Keysboard buttons

    This may be somewhere on FlashKit, but I cannot find it.

    Now, if I want to move a _mc, I know I can if I use the preprogrammed Keys like --on (keyPress "<Left>")-- for example, but I want to know how I can use the "A" Key, or some Key instead of their choice of Keys.

    In advance

    Thank You

  2. #2
    Get Squared Away.
    Join Date
    Feb 2000
    Location
    Allentown, PA
    Posts
    543
    you should use the built in getAscii() and getCode() functions.

    Good examples in flash help.

  3. #3
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    here's one i use a lot to find Code and Ascii values

    paste the code into a new fla and test in the published swf
    as Flash reserves certain keys for its own operations
    Code:
    this.createTextField("traceR1",10,100,50,0,0);
    this.createTextField("traceR2",20,100,100,0,0);
    traceR1.autoSize = traceR2.autoSize = true;
    
    aformat = new TextFormat();
    aformat.bold = true; aformat.size = 22; aformat.color = 0x0000FF;
     
    myObj = new Object();
    myObj.onKeyDown = function() {
    a = Key.getCode(); b = Key.getAscii(); c = String.fromCharCode(b);
    
    traceR1.text=traceR2.text="";
    traceR1.text="Key pressed: "+c+" -  getAscii: "+b+" - getCode: "+a;
    
    if(a>95 && a<106)traceR2.text= "NumPad - "+c+" - getCode: "+a;
    if(a>47 && a<58)traceR2.text= "Number - "+c+" - getCode: "+a;
    
    traceR1.setTextFormat(aformat); traceR2.setTextFormat(aformat);
    	};
    
    Key.addListener(myObj);

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    49
    TO: A Modified dog-I already know the ascii
    TO: Josiah I know about thise two as well, I just don't know how to use them.

    Maybe I'm not making myself clear enough, I would like to know how to use tha "A" button to make something move left or right.
    How and where would I place the getAscii() and getCode() functions?
    I have tried using these two, but nothing. After 4 hours trying to make it work, I turned it off.

    I know that Flash reserves certain keys for its own operations, I already wrote that.

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    49
    Oh sorry, I just discovered that I had the CODEs---NOT ASCII, that may have been my problem, I was using the codes in place of ascii.

    TO: A Modified dog: Never mind. Your program did help me discover this, so....

    Thank you- Thank you- Thank you- Thank you- Thank you.

    But any advice is still welcome.

  6. #6
    Get Squared Away.
    Join Date
    Feb 2000
    Location
    Allentown, PA
    Posts
    543
    you can use this as a guide...this will trace an output everytime you press D on your keyboard.

    Code:
    var keyListener:Object = new Object();
    keyListener.onKeyDown = function() {
    	if(Key.getCode() == 68){
    		trace("you pressed D");
    	}
    	
    };
    Key.addListener(keyListener);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center