我们知道在Symbian的按键事件处理中使用以下方法:
TKeyResponse CMegajoyContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
这个方法是在CCoeControl(Control base class from which all other controls are derived)中定义的虚函数,其定义如下:
|
|
Return value
|
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:
所以,从上面的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扫描码定义呢?如果是这样,是不是每个手机型号都要定义一个自己的扫描码头文件,那可是非常非常恐怖的一件事情。
|