Skip to main content
Inspiring
March 25, 2008
Question

Assigning Keyboard Actions

  • March 25, 2008
  • 4 replies
  • 377 views
Hello,

I am wanting my 'H' key to work. I have attached my code below. The function is basically triggered by an event handler from another function.

The code I have works if i want to assign a keycode for SPACEBAR etc however it doesnt work for H.

H only works with the keyCode 72 if the shift key is held in. This is not what I want, i simply want someone to press the H key only and they get the desired effect.

Can anyone help?

Thanks

Lee
This topic has been closed for replies.

4 replies

Participating Frequently
March 26, 2008
There is nothing wrong with your H key.
The problem is that if you run the file inside of Flash, the lower case h is trapped by Flash for its own use.
Run the .swf file outside of Flash and replace the trace with displays to a text field and you will see.
Participating Frequently
March 25, 2008
This is almost definitely because you are testing inside of Flash CS3, try testing in Flash Player or browser and it should work. For testing in flash just hold down the shift key.
March 25, 2008
note that i don't have Flash on right now, so I don't know whether it is working, you have to test it yourself.
March 25, 2008
Maybe try TextEvent?

import flash.events.TextEvent;

function keyH(event:TextEvent):void
{
var pressedKey:String = event.text;
if (pressedKey== "H")
{outputText.text = "You typed H: " + pressedKey;}
}

entryText.addEventListener(TextEvent.TEXT_INPUT, keyH);

I have two textfields here.you can do it like


import flash.events.TextEvent;

function keyH(event:TextEvent):void
{
var pressedKey:String = event.text;
if (pressedKey== "H"){
trace (pressedKey);
}
}
object.addEventListener(TextEvent.TEXT_INPUT, keyH);