捕获键盘事件CTRL + S [英] Capture keyboard event CTRL+s
本文介绍了捕获键盘事件CTRL + S的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要触发一个事件由pressing CTRL + S。
I need to fire an event by pressing CTRL+s.
我试过,但它不会工作:
I tried this but it won't work:
if(e.ctrlKey == true && e.keyCode == 81){
trace("CTRL+S")
}
如何能不能做到? 谢谢你的提示。
How can it be done? Thanks for tips.
推荐答案
这是关键code 83 S(的情况下,如果你犯那个错误)。此外,请确保您的KEY_UP事件添加监听器。以下是一个例子:
It is keyCode 83 for S (in case if you are making that mistake). Moreover, make sure you add your listener on KEY_UP event. Here is a working sample:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:Panel title="Panel 3" width="100%" height="200" creationComplete="onCreationComplete()">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Script>
<![CDATA[
private function onCreationComplete():void{
this.addEventListener(MouseEvent.CLICK, clickHandler);
this.addEventListener(KeyboardEvent.KEY_UP,keyPressed);
}
private function clickHandler(event:MouseEvent):void {
stage.focus = this;
}
private function keyPressed(evt:KeyboardEvent):void{
if(evt.ctrlKey && evt.keyCode == 65)
trace("CTRL A is pressed");
if(evt.ctrlKey && evt.keyCode == 66)
trace("CTRL B is pressed");
if(evt.ctrlKey && evt.keyCode == 81)
trace("CTRL S is pressed");
}
]]>
</fx:Script>
</s:Panel>
</s:WindowedApplication>
这篇关于捕获键盘事件CTRL + S的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文