You'll want to create a custom button component and override the keyDownHandler. But, if you want to pick the button(s) to be stopped, you need to add a conditional to the code. This is what it should look like:
package Sandbox
{
import mx.controls.Button;
import flash.events.KeyboardEvent;
public class KeyButton extends Button
{
public function KeyButton()
{
super();
}
protected override function keyDownHandler(e : KeyboardEvent) : void {
if (e.keyCode == 32) { // Spacebar
return;
}
else if (e.keyCode == 67) { // Letter C
this.parentApplication.setStyle ("backgroundColor", "#00aa00");
}
super.keyDownHandler (e);
}
}
}
The advantage of this is that other keys will still work, like Enter, or you can add more conditionals for different keys if, say, you wanted to change the color of the button if you pressed C or whatever.
And while we're at it, there is a difference between KeyboardEvent.keyCode and charCode. keyCode is the ID of the key on the physical keyboard, which means that lowercase c and capital C are the same (keyCode == 67). charCode, on the other hand, is the address of the character in the ASCII table, so c and C are different (C is 67 while c is 99). keyCode is case-insensitive, in short.
Oh, yes. And should you need to check the key and char codes of a key (including arbitary ones like Backspace), check out this page the good folks at Adobe made.
I also made an application to illustrate this. It's a standard Flex Builder project, but the source is in the src folder if you don't have it. Launch the application, and click the button to focus it. Some text should appear over the button, courtesy of the button's click event. While it has focus, press Spacebar, which should fire the click event and print more text, but nothing happens! Now, press the c key to change the background color of the application. Neat, eh?
You can find the source here.