Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 05-07-2008, 06:47 PM   #1
ecsancho
Senior Member
 
Join Date: Jul 2007
Posts: 172
Default Convert key code to string

I'm using

var keyListener:Object = new Object();
keyListener.onKeyDown = function() {

trace(Key.getAscii());

};
Key.addListener(keyListener);

But when I test it gives the value of the interger but how I do convert it so I actually have the letter of the key pressed? Thanks
ecsancho is offline   Reply With Quote
Old 05-07-2008, 07:07 PM   #2
xxneon
Super Moderator
 
xxneon's Avatar
 
Join Date: Dec 2006
Location: Amish Country, PA
Posts: 8,570
Send a message via ICQ to xxneon Send a message via AIM to xxneon Send a message via MSN to xxneon Send a message via Skype™ to xxneon
Default

this should do it.
trace(String.fromCharCode(Key.getCode());
__________________
Always optimizing...
xxneon is offline   Reply With Quote
Old 05-07-2008, 07:10 PM   #3
ecsancho
Senior Member
 
Join Date: Jul 2007
Posts: 172
Default

Thank you again neon
ecsancho is offline   Reply With Quote
Old 05-07-2008, 10:17 PM   #4
ecsancho
Senior Member
 
Join Date: Jul 2007
Posts: 172
Default

How can I make it run a function from a certain k to be pressed? For instance

Key.onPress (k) {
doafunction();
}
Thanks
ecsancho is offline   Reply With Quote
Old 05-08-2008, 02:34 AM   #5
xxneon
Super Moderator
 
xxneon's Avatar
 
Join Date: Dec 2006
Location: Amish Country, PA
Posts: 8,570
Send a message via ICQ to xxneon Send a message via AIM to xxneon Send a message via MSN to xxneon Send a message via Skype™ to xxneon
Default

in the listeners onKeyDown function you can do an if statement..

ActionScript Code:
if(Key.getCode() == String("q").charCodeAt(0)){     trace("the q is pressed"); }

check out flash help though.. there is alot of Key properties for specific character codes.. the example above is just a way so that you dont have to figure out what the code is.you just stick the letter you want in the ( ).. and it spits out the character code.. so it can be compared to the code of the last pressed key ..
__________________
Always optimizing...
xxneon is offline   Reply With Quote
Old 05-08-2008, 02:52 AM   #6
asf8
Senior Member
 
Join Date: Apr 2007
Posts: 4,772
Default

I use this when I need to get key codes, letters etc...

ActionScript Code:
var keyListener:Object = new Object(); keyListener.onKeyDown = function() {     trace("DOWN -> Code:");     trace("\tCode: "+Key.getCode());     trace("\tACSII: "+Key.getAscii());     trace("\tKey: "+chr(Key.getAscii()));     myTxt.text = ("\tCode: "+Key.getCode()+"\tACSII: "+Key.getAscii()+"\tKey: "+chr(Key.getAscii())); }; Key.addListener(keyListener);

Also here are some great posts by inhan and xxneon for using
if/else and switch/case with the key class and would be perfect for you.
http://www.actionscript.org/forums/s....php3?t=159333

Also here is a good link from Adobe:

Keyboard keys and key code values overview
http://livedocs.adobe.com/flash/mx20...=00001113.html

So you can use the code provided above, then use the codes in those links to create your events when specific keys are pressed.

Atleast I hope it helps. ;-)
asf8 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Convert ByteArray data into String and to store into a file on HD msajjadali ActionScript 3.0 6 04-24-2008 03:51 PM
convert string to number treysuttle78 ActionScript 2.0 9 04-24-2008 12:18 PM
how can I convert a string to another code? LionAlquds ActionScript 2.0 8 07-19-2006 01:50 PM
convert button event code to a function AND 'if,then,else' on a button event Cheska ActionScript 2.0 18 06-02-2006 10:10 PM
06++ = 7 != 07 Flash Gordon Server-Side Scripting 5 01-17-2006 06:27 PM


All times are GMT. The time now is 04:09 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.