I need an Event Listener for press Delete button from keyboard.
我需要一个事件监听器来按键盘上的删除按钮。
I try with this code:
我尝试使用此代码:
stage.addEventListener(KeyboardEvent.KEY_UP, deleteItem);
function deleteItem(e:KeyboardEvent) {
if(e.charCode == 46){
trace('1');
}
}
but don't work. Please help me!
但是不行。请帮我!
2 个解决方案
#1
0
stage.addEventListener(KeyboardEvent.KEY_UP, keyboardEventUPHandler, false, 0, true);
function keyboardEventUPHandler(event:KeyboardEvent):void
{
if(event.keyCode == Keyboard.DELETE)
{
//Keyboard.DELETE = 46
//do something
}
}
#2
-2
stage.addEventListener(KeyboardEvent.KEY_UP, deleteItem);
should be
stage.addEventListener(KeyboardEvent.KEY_DOWN, deleteItem);
#1
0
stage.addEventListener(KeyboardEvent.KEY_UP, keyboardEventUPHandler, false, 0, true);
function keyboardEventUPHandler(event:KeyboardEvent):void
{
if(event.keyCode == Keyboard.DELETE)
{
//Keyboard.DELETE = 46
//do something
}
}
#2
-2
stage.addEventListener(KeyboardEvent.KEY_UP, deleteItem);
should be
stage.addEventListener(KeyboardEvent.KEY_DOWN, deleteItem);