Hi all,
I’m not sure if this is the best place to post. Sorry if it’s not!
I’ve tried 4 or 5 different way’s of grabbing keyboard input in flash AS3, but each time I can get the cursor keys, shift, space, the number keys and the numpad, but I can’t get any of the character keys “q,w,e,r,t,y,etc…” or the enter key to trace any output!
Has anyone come across this before?!
I know I’ve been able to use the character keys and enter in the past!
Could it be something to do with my keyboard or have I forgotten something in Flash?
Here’s the current code I’m using. This works with some keys and not others, just like every other attempt I’ve made!
public 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( "" );
}
Thanks