作者:孙东风    文章来源:本站原创    更新时间:2007-7-9 8:38:34

我们知道在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: EEventKeyEEventKeyUp 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:

Struct 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
iCodeiModifiersiRepeatsiScanCode

Member data


iCode

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中定义。


iModifiers

TUint iModifiers

Description

State of modifier keys and pointing device. Modifier keys are defined in TEventModifier.


iRepeats

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.


iScanCode

TInt iScanCode

Description

The scan code of the key that caused the event.

Standard scan codes are defined in TStdScanCode.

所以,从上面的SDK HELP可以看出来:iScanCode这个值是实际键盘的扫描码,也就是一个键对应一个数字。而iCode是键的一些映射,比如EKeyLeftArrowEKeyRightArrowEKeyUpArrowEKeyDownArrow、EKeyDevice3分别代表左、右、上、下、Fire键,而63554、63555分别代表左右软键等。

所以用iCode具有更强的通用性,不会出现下面的问题:

我写了一个程序,用CAknView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)接受键盘事件,仅仅处理"*"按键,我发现,Symbian定义的EStdKeyNkpAsterisk值为133,在模拟器上工作正常,可是转到我的Nokia 6060后,失败了,后来发现Nokia 6060对"*"的扫描码为40,我很困惑的是如果每个手机都定义了自己的扫描码系统,那么Symbian定义扫描码常量的作用是什么呢,指导作用?另外,是不是所有手机都不遵循Symbian扫描码定义呢?如果是这样,是不是每个手机型号都要定义一个自己的扫描码头文件,那可是非常非常恐怖的一件事情。

转载于:https://www.cnblogs.com/yaoliang11/archive/2010/10/28/1863593.html

Symbian中的iScanCode和iCode(转)相关推荐

  1. Symbian中的新手问题整理(二)

    最近变得有点懒了,博客也一直没有更新,最近在Symbian的论坛呆的时间比较多,但还是觉得博客园的博客系统最好最稳定. 1.关于Symbian 3rd以后的能力问题 Symbian也是从3rd后才引入 ...

  2. Symbian中不能跨越线程(RThread)使用的对象/组件(RSocket/Memery Heap,etc)

    在Symbian C++的编程中,出现一很多与Windows/linux用法与概念不同的东西. 首先,在Symbian中不建议多线程,因为线程的开销,也因为线程之间有很多东西不能传递与共享(虽然同一进 ...

  3. Symbian中卡拉OK字幕实现

    Symbian中卡拉OK字幕实现 <script type="text/javascript"> document.body.oncopy = function() { ...

  4. Symbian中的进程和线程

    <Symbian OS:线程编程> Symbian操作系统中的线程和进程 在Symbian操作系统中,每个进程都有一个或多个线程.线程是执行的基本单位.一个进程的主线程是在进程启动时生成的 ...

  5. symbian 中自动寻找cmwap连接点,通杀uiq 2nd 3nd和s60 2nd 3nd 5nd

    全测试过了,鉴于手机型号太多,没有一一的测试. 找不到连接点,应该自动创建一个的,但这个需要证书,就没写了. 今天发现刷了机的一个5800连不上,在二级查找上,还需比较一下名字. //寻找可用的连接点 ...

  6. Symbian 开发知识

    找资料的时候发现这个不错就转过来啦 Symbian 开发知识,琐碎篇 General Hints / 一般提示 学习S2,我的方法无非是: ·每天coding,多少小时你自己掌握,看你有多少时间了. ...

  7. Symbian开发系列 - 入门篇

    要开始我的Symbian开发之旅了, 先收集一些相关资料,如Symbian概述, 开发平台搭建, 参考书籍与网络资源. [基础] 什么是Symbian 学习Symbian的基本概念  Symbian操 ...

  8. Symbian编程VC开发环境设置

    1 安装SDK及VC Nokia根据手机的屏幕大小和价格高低把手机分成了多个系列,现在使用的系列有:Series 40.Series 60.Series 80 和Series 90.60系列采用Sym ...

  9. Symbian手记【三】 —— Symbian的描述符

    [三] Symbian的描述符 所谓描述符,一定程度上等同于字符串.只不过与C++的字符串不一样,Symbian中的描述符都是用一个附加的整数描述其长度,而不是以'\0'做终结符.因此,描述符可以表达 ...

  10. Symbian手记【二】 —— Symbian对象构造

    [二] Symbian对象构造 C++的纯手工内存管理,确实是一个万恶之源.在对象构造时,有一个著名的内存泄漏隐患问题.比如一个类如下: class A { public:         A()   ...

最新文章

  1. 关于Kafka Spring Boot的教程
  2. 反思脑机接口技术:机器真的能控制我们的大脑吗?
  3. python在财务上的应用-致工作党:Python这项技能你一定要会
  4. PUSH进栈指令和POP出栈指令
  5. 【转】 GetProcAddress()用法
  6. TS字面量进行类型声明
  7. android 监听本机网络请求_fiddler如何抓取https请求实现fiddler手机抓包-证书安装失败100%解决...
  8. linux:tomcat写入文件失败
  9. delphi trichviewedit 设置一行的段落_HTML中的文本与段落(3)
  10. CSS3鼠标悬停360度旋转效果
  11. oracle的多个exclude,记录一下expdp exclude的用法
  12. Codeforces 106 Buns【多重背包】
  13. 华为鸿蒙系统平板电脑,华为5G鸿蒙系统平板电脑正式入网,搭载八核处理器麒麟9000芯片...
  14. 实用且堪称神器的 Chrome 插件推荐(值得收藏)
  15. linux轻量级进程,linux轻量级进程LWP
  16. 将安卓手机屏幕内容投射到电脑屏幕上
  17. 世界名校排名2020
  18. CSS全科教程——第一部分:CSS基础
  19. 微信小程序网址请求封装
  20. 日本价值链促进会(IVI)秘书长西冈靖之:日本工业互联网发展情况

热门文章

  1. 分享三种计算机专业毕业设计模板附下载地址
  2. linux命令mysql启动,linux中mysql启动服务命令
  3. 人工神经网络翻译的优点,神经网络机器翻译技术
  4. c++打开图片查看器并查看图片
  5. win10系统的电脑如何录屏?QVE录屏大师使用教程?
  6. SCT芯洲DC-DC-SCT2430是一款输出电流高达3.5A的高功率密度全集成同步降压DCDC转换器。其输入电压范围为3.8V到40V,替代TPS54340
  7. oracle----globle temp table
  8. 仿真工具NS3的基本知识
  9. Pyqt QThread
  10. matlab电气应用,基于MATLAB/Simulink的高压直流输电系统的仿真研究.pdf