WEB开发网
开发学院手机开发Symbian 开发 Symbian捕获全局按键的解决方案 阅读

Symbian捕获全局按键的解决方案

 2010-02-06 20:55:00 来源:WEB开发网   
核心提示:// (只有这样才会收到窗口服务器的消息)让当前窗口群在任务切换列表中隐藏起来void CGlobalCapturer::StartCapturingL(){// Connect to the window serverUser::LeaveIfError( iWsSession.Connect() );// Crea

// (只有这样才会收到窗口服务器的消息)让当前窗口群在任务切换列表中隐藏起来

void CGlobalCapturer::StartCapturingL()

{

// Connect to the window server

User::LeaveIfError( iWsSession.Connect() );

// Create an invisible window group. Well, we'll make it invisible later

iWindowGroup = new (ELeave) RWindowGroup ( iWsSession );

// @see RBlankWindow::Construct,这是空窗口的初始化

iWindowGroup->Construct( (TUint32)iWindowGroup, EFalse );

// Capture a key

User::LeaveIfError( iCaptureHandle = iWindowGroup->CaptureKey( KKeyCode , 0, 0 ) );

// Send created window to the background and hide it from the

// application switcher,这里就是隐藏窗口群了

iWindowGroup->SetOrdinalPosition(-1);

iWindowGroup->EnableReceiptOfFocus( EFalse );

iWindowGroupName = CApaWindowGroupName::NewL( iWsSession );

iWindowGroupName->SetHidden(ETrue);

iWindowGroupName->SetWindowGroupName( *iWindowGroup );

// Tell window server, that we are ready to receive events

// 这里就是进入了等待过程,由于传入了iStatus,系统自动处于阻塞状态,除非左方向键被按下,否则就会

//一直阻塞,无法运行活动对象的RunL函数

iWsSession.EventReady( &this->iStatus );

CActiveScheduler::Add( this );

SetActive();

}

// Key press happened

// 这里才是真正的截获全局按键的处理函数,放在活动对象里面了

void CGlobalCapturer::RunL()

{

if( iStatus == KErrNone )

{

// EEventKey received

console->Write( _L( "Captured key press " ) );

TWsEvent we;

iWsSession.GetEvent( we );

if( we.Key()->iCode == KKeyCode )

{

console->Printf( _L( "Captured correct key press for the %i time " ),

上一页  1 2 3 4 5 6  下一页

Tags:Symbian 捕获 全局

编辑录入:coldstar [复制链接] [打 印]
赞助商链接