Symbian捕获全局按键的解决方案
2010-02-06 20:55:00 来源:WEB开发网// 定义需要捕获的全局按键,这里是Left Arrow,左方向键
const TUint KKeyCode = EKeyLeftArrow;
// Capture KNumberOfPressesToCapture key presses
// 定义捕获多少次的,这里只定义了3次,可以根据需要修改
const TInt KNumberOfPressesToCapture = 3;
// Global Variables
// write all messages to this console
// 用于显示的console,可以根据需要改成别的,不过最好不要用于做违法的事情。
LOCAL_D CConsoleBase* console;
// Local Functions
// 创建按键捕获类的对象capture,并做了一些异常防护工作。然后调用capturer->StartCapturingL()初始化
//活动对象
LOCAL_C void MainL(const TDesC& )
{
console->Write( _L( "Starting key capturing " ) );
// Create capturer
CGlobalCapturer* capturer = new (ELeave) CGlobalCapturer();
CleanupStack::PushL( capturer );
// And start capturing
capturer->StartCapturingL();
// In a real application you should use CActiveSchedulerWait,
// but in this small demo application we know that there is just
// a single inner loop and no CActiveSchedulerWait "protection" is
// needed
CActiveScheduler::Start();
// Cleanup. Demo completed
CleanupStack::PopAndDestroy( capturer );
}
// Main function. Is TRAPD outside, in Start()
// 创建用于按键捕获的活动对象调度器然后调用MainL(symbian是多么?嗦的一个系统啊,需要绕这么多圈
//子,不过这些都是为了保证系统可以“万无一失”的运行)
LOCAL_C void DoStartL()
{
// Create active scheduler (to run active objects)
CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
CleanupStack::PushL(scheduler);
CActiveScheduler::Install(scheduler);
// Call main function with command line
// Command line is not really needed for this demo, but
更多精彩
赞助商链接