hi guys, I want to find out how to get capital letter keyCode
The code below returns the ascii number of the keys located on the keyboard.
But those are uppercase case. How about lower case?
Example: when i press/hit the key ‘a’ it returns 65.
In the ascii chart, 65 is capital A.
When I try SHIFT + ‘a’, it returns 16 and 65.
How to solve this?
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);
function keyDown(event:KeyboardEvent):void {
trace(event.keyCode);
}
edit: found my solution here. Credits to Nutrox on UltraShock
http://www.ultrashock.com/forums/actionscript/keypress-for-as3-96851.html
stage.addEventListener( KeyboardEvent.KEY_DOWN, keyDownHandler );
stage.addEventListener( KeyboardEvent.KEY_UP, keyUpHandler );
var pressedKeys:Object = {};
function keyDownHandler( e:KeyboardEvent ):void
{
// The keyDown event is repeatedly fired while a key is
// held down, so we can do this to ensure we only deal with
// the event the first time a key is pressed.
if( pressedKeys[ e.keyCode ] )
{
return;
}
pressedKeys[ e.keyCode ] = 1;
//
trace( "KEY PRESSED" );
traceEvent( e );
}
function keyUpHandler( e:KeyboardEvent ):void
{
delete pressedKeys[ e.keyCode ];
trace( "KEY RELEASED" );
traceEvent( e );
}
function traceEvent( e:KeyboardEvent ):void
{
trace( "keyCode ", e.keyCode );
trace( "charCode ", e.charCode );
trace( "character ", String.fromCharCode( e.charCode ) );
trace( "" );
}