使用 Animation dll 捕获按键

来源:互联网 发布:phpstorm 调试js 编辑:程序博客网 时间:2024/04/29 13:07

Capturing key events using Animation dll
使用 Animation dll 捕获按键
====================================================
Platform  
-----------------------------------
S60 3rd Edition, FP1
S60 3rd Edition, FP2
S60 5th Edition  

Tested on devices
-----------------------------------
Tested on Nokia N95,
Navi 6210,
Nokia 5800 XpressMusic

Keywords (APIs, classes, methods, functions):
------------------------------------------------
 Animation dll, CAnim, RAnim, raw events

==========================================================================
Overview
----------------------------
An animation DLL defines a framework for polymorphic DLLs that perform animations.
However, it can also be used to get the raw window server events.
This article provides an additional aspect of capturing raw events using an animation DLL.
The animation example already present in S60 examples does not include code for raw event handling.
All the raw events can be received and handled in MEventHandler::OfferRawEvent().
This function is implemented in an CAnim-derived class.
This function should return EFalse, otherwise the foreground application or applications
that have registered to get key events using RWindowGroup::CaptureKey() will not receive them.

一个 animation dll 定义了一个完成动画的多态DLL框架。然而,他也可以被用作获取原始window服务器事件。
这篇文章提供了一个额外的方面,来使用animation DLL 捕获原始事件。
S60例子中animation的例子并不包括原始事件处理的代码,所有的原始事件可以在MEventHandler::OfferRawEvent()中接收和处理。
这个函数实现在一个CAnim子类中,这个函数应该返回EFalse,
否则前台程序或者使用RWindowGroup::CaptureKey()注册来得到按键事件的程序不会再得到事件了。

TBool CImage::OfferRawEvent( const TRawEvent& aRawEvent )
   {
   // 捕获 '0' 键
   if(aRawEvent.Type()==TRawEvent::EKeyDown && aRawEvent.ScanCode()=='0')
     {
     // 事件处理代码
     }
   return EFalse;
   }

These events are offered to MEventHandler::OfferRawEvent() only if raw event handling is switched on.
This is done by calling MAnimGeneralFunctions::GetRawEvents(ETrue).
An object of class MAnimGeneralFunctions is not created.
The class is implemented by the window server and provides utility functions
to all CAnim-derived classes via CAnim::iFunctions pointer.
So in order to receive raw events,
add the following code to ConstructL of the CAnim-derived class:

这些事件只有在原始事件处理开启时 才会提供给 MEventHandler::OfferRawEvent() 。
这就需要调用 MAnimGeneralFunctions::GetRawEvents(ETrue)。
一个MAnimGeneralFunctions 类的事件并未被创建,这个类被window服务器实现,通过CAnim::iFunctions指针提供工具函数给所有的CAnim子类。
所以为了得到原始事件,添加下列代码到 CAnim子类的ConstructL中。

void CImage::ConstructL( TAny* /*aArgs*/, TBool /*aHasFocus*/ )
   {  
    iFunctions->GetRawEvents(ETrue);  
   }

原创粉丝点击