Symbian捕获全局按键的解决方案
2010-02-06 20:55:00 来源:WEB开发网// (只有这样才会收到窗口服务器的消息)让当前窗口群在任务切换列表中隐藏起来
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 " ),
更多精彩
赞助商链接