简体   繁体   中英

Detecting KeyBoard events inside NumericStepper

I have a movie clip with 2 buttons (Ok and Cancel) and one Numeric Stepper.

If the user press enter key on the keyboard I want that "Ok" button function runs and if "BackSpace" is pressed "Cancel" function.

I have this code that detect when I press almost all the keys but not when I press "ENTER" or "BACKSPACE".

stage.addEventListener(KeyboardEvent.KEY_UP, onKeyPressed);

function onKeyPressed(event:KeyboardEvent):void
{

 if (event.keyCode==Keyboard.ENTER) {
       okBtnFunction();
 }
 if (event.keyCode==Keyboard.DELETE) {
       cancelBtnFunction();
 }
}

I also tried with event.charCode.

Enter and Backspace keys aren't enable because of the flash shortcut, you can see it in this link:

Flash AS3: ENTER does not get detected, but CTRL+ENTER works fine

If you try to get keyboard event inside NumericStepper you have to use:

Object(this).YOU_NUMERIC_STEPPER.textField.addEventListener(KeyboardEvent.KEY_DOWN, keyboard_handler); 

Remember to use textField after numeric stepper name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM