Detect a key in an input field

I have an input text field (myText_txt) and I want to detect whether a certain key has been pressed and if so I take an action. I have two lots of code so far but neither works. Any ideas?

// in this one I set up a listener and apply it to the myText_txt

myListener = new Object();
myListener.onKeyDown = function() {
if(Key.isDown(Key.SPACE)) {
trace(“space bar”);
}
}
myText_txt.addListener(myListener);

// in this one I apply the onChanged to the myText_txt

myText_txt.onChanged = function () {
if (key.isDown(Key.SPACE)) {
trace(“space bar”);
}
}

neither of them detect the space bar key press. Is it possible to do this to an input field ??

I only want to pick up the key press within the text field.

thanks