我们知道在Symbian的按键事件处理中使用以下方法:
TKeyResponse CMegajoyContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
这个方法是在CCoeControl(Control base class from which all other controls are derived)中定义的虚函数,其定义如下:
OfferKeyEventL()
virtual TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
Description
Handles key events.
If a control wishes to process key events, it should implement this function. The implementation must ensure that the function returns EKeyWasNotConsumed if it does not do anything in response to a key event— otherwise, other controls or dialogs may be prevented from receiving the key event. If it is able to process the event it should return EKeyWasConsumed .
注释:
如果一个控件希望处理按键事件,那么它就应该实现这个函数。如果对一个按键事件,控件并没做任何事情,那么函数的实现中必须确保函数返回EKeyWasNotConsumed。否则,(控件栈中的)其它控件或对话框可能会接收不到按键事件。如果此控件能够处理按键事件,那么它应该返回EKeyWasConsumed。
When a key event occurs, the control framework calls this function for each control on the control stack, until one of them can process the key event (and returns EKeyWasConsumed ).
注释:
当一个按键事件发生时,控件框架调用控件栈上的每个控件的OfferKeyEventL方法,直到它们中的一个能够处理这个按键事件(并且返回EKeyWasConsumed)。
Parameters
const TKeyEvent& aKeyEvent |
The key event.
|
TEventCode aType |
The type of key event: EEventKey , EEventKeyUp or EEventKeyDown .
|
|
Return value
TKeyResponse |
Indicates whether or not the key event was used by this control.
|
|
Notes:
- Each keyboard key press results in three separate events: EEventKeyDown, EEventKey, and EEventKeyUp, in that order.
每个键被按下时会顺序产生三个独立的事件:EEventKeyDown、EEventKey、EEventKeyUp。
- To receive key events, which can be processed by this function, the application should call CCoeAppUi::AddToStackL() to add the control to the stack. This only applies, however, to controls which are not components of a compound control. Compound controls should pass key events to their components as necessary: the components themselves do not go on the stack.
为了接收到按键事件,应用程序应该调用CCoeAppUi::AddToStackL() 方法把控件增加到栈上。尽管这个规则仅仅用在非混合控件。混合控件应该传递按键事件给其组件:组件自己并不在控件栈上。
- Classes that override CCoeControl::OfferKeyEventL() should also override the InputCapabilities() virtual function, returning a TCoeInputCapabilities object whose attributes correspond to the behaviour of the OfferKeyEventL() function. Note that it is not necessary to call InputCapabilities() on any component controls from inside a class' InputCapabilities() function — this is done automatically by the UI Control Framework.
重载CCoeControl::OfferKeyEventL()的类也应该重载虚函数InputCapabilities() ,它会返回一个TCoeInputCapabilities 对象,这个对象的属性和OfferKeyEventL()方法的行为吻合。注意,在控件中并不是必须要调用InputCapabilities() 方法,因为这个过程自动被UI Control Framework完成了。
|
virtual TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
中的第二个参数没什么好说的,它就代表三种按键事件中的一种,我们重点来看看TKeyEvent:
TKeyEvent
Support
Supported from 5.0
Description
Key event details.
When processing a TKeyEvent , the TStdScanCode in iScanCode should usually be ignored in favour of the TKeyCode in iCode . Using iScanCode would bypass the keyboard mapping and any FEP that happens to be installed. The exceptions to this general rule are games where the positions of the keys are more important than their translations, and FEPs that are implementing keyboard maps themselves. In these cases, if the iCode is used rather than iScanCode to determine the key pressed, there will be two unfortunate consequences. Firstly, the low-level keyboard mapping might re-arrange the mapping that you are trying to impose. Secondly, you will subvert the CTRL+number method of entering Unicode literals.
注释:
当处理一个TKeyEvent时,TStdScanCode中的iScanCode通常应该被忽略而赞成用TKeyCode中的iCode。用iScanCode可以绕过键盘映射和任何已经安装的FEP(A front-end processor)。这个规则的例外情况是游戏,因为游戏中键盘的方位比它们实际的值更重要,还有FEP中,它们已经实现了键盘映射。在这些情况下,用iCode去决定按键,会有两个意外的后果。首先,底层的键盘映射机制可能会重新布置键盘映射。其次,你会破坏输入Unicode字符的CTRL+number方法。
Members
Defined in TKeyEvent :
iCode , iModifiers , iRepeats , iScanCode
Member data
TUint iCode
Description
The character code generated for an EEventKey , or 0 for a down or up event.
Key codes for special keys are defined in TKeyCode .
对应一个EEventKey产生的字符码,当按下或释放按键的时候值为0(这点需要注意,我测试的时候,没按键的时候屏幕上值为0,只有当键被按超过几s时才会有相应的值产生,当释放按键的时候值也为0,所以你如果写成下面的代码值就始终为0,测试不出来实际的值:
if( aType == EEventKeyDown ){ TBuf<40> scanCode; scanCode.AppendNum(aKeyEvent.iCode); scanCode.operator +=_L(" iScanCode is pressed down!"); CEikonEnv::Static()->InfoMsg(scanCode); }
所以应该写成下面这样:
if( aType == EEventKey ){ TBuf<40> scanCode; scanCode.AppendNum(aKeyEvent.iCode); scanCode.operator +=_L(" iScanCode is pressed down!"); CEikonEnv::Static()->InfoMsg(scanCode); }
当aType为EEventKeyDown或EEventKeyUp时,iCode的值均为0
)。
特定按键的Key codes在TKeyCode中定义。
TUint iModifiers
Description
State of modifier keys and pointing device. Modifier keys are defined in TEventModifier .
TInt iRepeats
Description
Count of auto repeats generated.
0 means an event without repeats. 1 or more means "this many auto repeat events". It is normal to ignore this value and treat it as a single event.
TInt iScanCode
Description
The scan code of the key that caused the event.
Standard scan codes are defined in TStdScanCode .
|
所以,从上面的SDK HELP可以看出来:iScanCode这个值是实际键盘的扫描码,也就是一个键对应一个数字。而iCode是键的一些映射,比如EKeyLeftArrow
、EKeyRightArrow
、EKeyUpArrow
、EKeyDownArrow
、EKeyDevice3分别代表左、右、上、下、Fire键,而63554、63555分别代表左右软键等。
所以用iCode具有更强的通用性,不会出现下面的问题:
我写了一个程序,用CAknView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)接受键盘事件,仅仅处理"*"按键,我发现,Symbian定义的EStdKeyNkpAsterisk值为133,在模拟器上工作正常,可是转到我的Nokia 6060后,失败了,后来发现Nokia 6060对"*"的扫描码为40,我很困惑的是如果每个手机都定义了自己的扫描码系统,那么Symbian定义扫描码常量的作用是什么呢,指导作用?另外,是不是所有手机都不遵循Symbian扫描码定义呢?如果是这样,是不是每个手机型号都要定义一个自己的扫描码头文件,那可是非常非常恐怖的一件事情。
|
分享到:
相关推荐
通过对Symbian系统中左右软键处理的分析,我们可以看到,通过适当的编程技巧和资源文件配置,开发者可以灵活地控制这些按键的功能,从而提升用户的交互体验。无论是通过代码直接处理按键事件,还是通过资源文件定义...
我用carbide c++ 可以断点 不用这个 但是nokia不同机器型号的键值不同 倒是没见到过 想起原来有个自己写的练手的小东西 就发出来把 可以检测symbian s60 2nd的按键iscancode 也许有人有用吧
Symbian 是一款曾经非常流行的移动操作系统,在其发展过程中,开发者们遇到了各种各样的需求和技术挑战。其中,模拟按键事件是在 Symbian 应用开发中一个常见的需求。本文将详细介绍在 Symbian 平台上模拟按键事件的...
在Symbian操作系统中,模拟按键是一项非常实用的功能,尤其是在测试和开发阶段。通过模拟按键事件,开发者可以更容易地调试应用程序的行为,确保用户界面按照预期响应各种按键操作。本文将详细介绍Symbian系统中模拟...
【低空经济】低空人工智能调度中心建设方案
少儿编程scratch项目源代码文件案例素材-诅咒大厦.zip
scratch少儿编程逻辑思维游戏源码-纸片马里奥 激流勇进.zip
scratch少儿编程逻辑思维游戏源码-一路跳跃.zip
内容概要:本文详细介绍了五个用于空气耦合超声仿真的COMSOL模型,涵盖二维和三维场景,适用于铝板和钢板的多种缺陷检测。每个模型都包含了具体的参数设置、边界条件选择以及优化技巧。例如,Lamb波检测模型展示了如何利用A0模态检测铝板内的气泡,而三维模型则强调了内存管理和入射角参数化扫描的重要性。表面波检测模型提供了裂纹识别的相关性分析方法,变厚度模型则展示了如何通过几何参数化来模拟复杂的工件形态。文中还分享了许多实用的操作技巧,如内存优化、信号处理和自动化检测逻辑。 适用人群:从事无损检测研究的技术人员、COMSOL软件使用者、超声检测领域的研究人员。 使用场景及目标:①帮助用户理解和掌握空气耦合超声仿真的具体实现方法;②提供实际工程应用中的缺陷检测解决方案;③指导用户进行高效的仿真建模和结果分析。 其他说明:文中提供的模型不仅涵盖了常见的缺陷检测场景,还包括了一些高级技巧,如参数化扫描、自动化检测逻辑等,能够显著提高工作效率。同时,文中还给出了硬件配置建议和一些常见的注意事项,确保用户可以顺利运行这些模型。
实训商业源码-【脐橙】租赁 2.80.0+租赁商家-毕业设计.zip
scratch少儿编程逻辑思维游戏源码-幽灵冲刺.zip
scratch少儿编程逻辑思维游戏源码-粘粘世界物理.zip
机器人开发教程&案例&相关项目资源,奖励仅
实训商业源码-酒吧微上墙4.1.0-毕业设计.zip
实训商业源码-会员计次卡V1.1.1-毕业设计.zip
实训商业源码-二手跳蚤市场V5.4.10带微信支付+上架通知+广告插件-毕业设计.zip
实训商业源码-健康保健类企业网站源码-毕业设计.zip
Linux环境安装mysql的RPM包以及安装步骤:客户端和服务端的安装
实训商业源码-房产中介小程序8.0.51+前端-毕业设计.zip
scratch少儿编程逻辑思维游戏源码-钟声.zip