⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mguardkeycapture.cpp

📁 symbian s60手机上的短信拦截源代码。
💻 CPP
字号:
/*
* ============================================================================
*  Name     :  MGuardKeyCapture.cpp
*  Part of  :  MGuard
*  Created  :  July 21 by xueyw
*  Description:
*  Copyright: 
* ============================================================================
*/


//  Include Files  

#include "MGuardKeyCapture.h"
#include <e32base.h>
#include <e32std.h>
#include <apgwgnam.h>           // CApaWindowGroupName
#include <aknkeylock.h> 
#include <apacmdln.h>
#include <eikdll.h>


// Capture KNumberOfPressesToCapture key presses
const TInt KNumberOfPressesToCapture = 3;


////////////////////////////////////
// CGuardKeyCapturer
////////////////////////////////////

// Constructor
//	CGuardKeyCapturer CGuardKeyCapturer::iKeyCapture;

CGuardKeyCapturer::CGuardKeyCapturer() :CActive( EPriorityNormal )
{
	iCaptureStarted = EFalse;
	iCapturePending = EFalse;
	iCaptureHandleCount = 0;
	
		// Connect to the window server
	User::LeaveIfError( iWsSession.Connect() );
	// Create an invisible window group. Well, we'll make it invisible later
	/** @todo Can ELeave be used with R-classes? */
	iWindowGroup = new (ELeave) RWindowGroup ( iWsSession );
	// @see RBlankWindow::Construct
	iWindowGroup->Construct( (TUint32)iWindowGroup, EFalse );

}

// Destructor
CGuardKeyCapturer::~CGuardKeyCapturer()
{
	delete iWindowGroupName;
	delete iWindowGroup;
	iWsSession.Close();
}

// Cancel listening to key presses
void CGuardKeyCapturer::DoCancel()
{
	for ( TInt aIndex = 0; aIndex < iCaptureHandleCount; aIndex ++ )
	{
		iWindowGroup->CancelCaptureKey( iCaptureHandle[ aIndex ] );
	}
	
	RAknKeyLock keyLock; // first step

	//	Lock keyboard
	User::LeaveIfError(keyLock.Connect());  // second step
	CleanupClosePushL(keyLock);

	keyLock.DisableKeyLock(); // third step

	keyLock.Close(); // fourth step
	CleanupStack::PopAndDestroy(); // keyLock

}


void CGuardKeyCapturer::StopCapturingL()
{
	for ( TInt aIndex = 0; aIndex < iCaptureHandleCount; aIndex ++ )
	{
		iWindowGroup->CancelCaptureKey( iCaptureHandle[ aIndex ] );
	}

	
	RAknKeyLock keyLock; // first step

	//	Lock keyboard
	User::LeaveIfError(keyLock.Connect());  // second step
	CleanupClosePushL(keyLock);

	keyLock.DisableKeyLock(); // third step

	keyLock.Close(); // fourth step
	CleanupStack::PopAndDestroy(); // keyLock
		
	iCaptureHandleCount = 0;
	iCapturePending = ETrue;
}

void CGuardKeyCapturer::ResumeCapturingL()
{
	iCaptureHandleCount = 0;
	for ( TUint ii = 48; ii <= 57; ii ++ )
	{
		User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( ii , 0, 0 ) );
		iCaptureHandleCount ++;
	}

	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( 42 , 0, 0 ) );
	iCaptureHandleCount ++;
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( 35 , 0, 0 ) );
	iCaptureHandleCount ++;

	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( EKeyNull , 0, 0 ) );
	iCaptureHandleCount ++;
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( EKeyBell , 0, 0 ) );	
	iCaptureHandleCount ++;
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( EKeyBackspace , 0, 0 ) );	
	iCaptureHandleCount ++;
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( EKeyTab , 0, 0 ) );	
	iCaptureHandleCount ++;
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( EKeyLineFeed , 0, 0 ) );
	iCaptureHandleCount ++;
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( EKeyVerticalTab , 0, 0 ) );	
	iCaptureHandleCount ++;
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( EKeyFormFeed , 0, 0 ) );	
	iCaptureHandleCount ++;
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( EKeyEnter , 0, 0 ) );	
	iCaptureHandleCount ++;
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( EKeyEscape , 0, 0 ) );
	iCaptureHandleCount ++;
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( EKeySpace , 0, 0 ) );	
	iCaptureHandleCount ++;
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( EKeyDelete , 0, 0 ) );	
	iCaptureHandleCount ++;
	//
	for ( TInt aCode = EKeyPrintScreen; aCode < EKeyPrintScreen + 68; aCode ++ )
	{
		User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( aCode , 0, 0 ) );
		iCaptureHandleCount ++;
	}

	for ( TInt aCode = EKeyPrintScreen + 69; aCode < EKeyDecBrightness; aCode ++ )
	{
		User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( aCode , 0, 0 ) );
		iCaptureHandleCount ++;
	}

	iCapturePending = EFalse;	
	
	RAknKeyLock keyLock; // first step

	//	Start phone app
	_LIT(KPhoneAppPath, "\\system\\apps\\phone\\phone.app");
	{
		//	Open with the default/last known app
		CApaCommandLine * cmd = CApaCommandLine::NewL();        
		cmd->SetLibraryNameL( KPhoneAppPath );        
		cmd->SetCommandL( EApaCommandOpen );

		EikDll::StartAppL( *cmd );

		delete cmd;
	}

	//	Lock keyboard
	User::LeaveIfError(keyLock.Connect());  // second step
	CleanupClosePushL(keyLock);

	keyLock.EnableKeyLock(); // third step

	keyLock.Close(); // fourth step
	CleanupStack::PopAndDestroy(); // keyLock	
}

void CGuardKeyCapturer::StartCapturingL() 
{
	// You cannot just call CaptureLongKey for the same key code
	// You MUST call CaptureKey first

	iCaptureHandleCount = 0;
	for ( TUint ii = 48; ii <= 57; ii ++ )
	{
		User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( ii , 0, 0 ) );
		iCaptureHandleCount ++;
	}
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( 42 , 0, 0 ) );
	iCaptureHandleCount ++;
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( 35 , 0, 0 ) );
	iCaptureHandleCount ++;


	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( EKeyNull , 0, 0 ) );
	iCaptureHandleCount ++;
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( EKeyBell , 0, 0 ) );	
	iCaptureHandleCount ++;
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( EKeyBackspace , 0, 0 ) );	
	iCaptureHandleCount ++;
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( EKeyTab , 0, 0 ) );	
	iCaptureHandleCount ++;
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( EKeyLineFeed , 0, 0 ) );
	iCaptureHandleCount ++;
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( EKeyVerticalTab , 0, 0 ) );	
	iCaptureHandleCount ++;
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( EKeyFormFeed , 0, 0 ) );	
	iCaptureHandleCount ++;
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( EKeyEnter , 0, 0 ) );	
	iCaptureHandleCount ++;
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( EKeyEscape , 0, 0 ) );
	iCaptureHandleCount ++;
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( EKeySpace , 0, 0 ) );	
	iCaptureHandleCount ++;
	User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( EKeyDelete , 0, 0 ) );	
	iCaptureHandleCount ++;
	//
	for ( TInt aCode = EKeyPrintScreen; aCode < EKeyPrintScreen + 68; aCode ++ )
	{
		User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( aCode , 0, 0 ) );
		iCaptureHandleCount ++;
	}

	for ( TInt aCode = EKeyPrintScreen + 69; aCode < EKeyDecBrightness; aCode ++ )
	{
		User::LeaveIfError( iCaptureHandle[iCaptureHandleCount] = iWindowGroup->CaptureKey( aCode , 0, 0 ) );
		iCaptureHandleCount ++;
	}
	//
	// 	And finally capture long key presses
	//	User::LeaveIfError( iLongCaptureHandle = iWindowGroup->CaptureLongKey( KKeyCode , KKeyCode, 0, 0, 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
	//	It's first time

	iWsSession.EventReady( &this->iStatus );
	CActiveScheduler::Add( this );
	
	iCaptureStarted = ETrue;

	SetActive();
	
//	RAknKeyLock keyLock; // first step
//
//	//	Start phone app
//	_LIT(KPhoneAppPath, "\\system\\apps\\phone\\phone.app");
//	{
//		//	Open with the default/last known app
//		CApaCommandLine * cmd = CApaCommandLine::NewL();        
//		cmd->SetLibraryNameL( KPhoneAppPath );        
//		cmd->SetCommandL( EApaCommandOpen );
//
//		EikDll::StartAppL( *cmd );
//
//		delete cmd;
//	}
//
//	//	Lock keyboard
//	User::LeaveIfError(keyLock.Connect());  // second step
//	CleanupClosePushL(keyLock);
//
//	keyLock.EnableKeyLock(); // third step
//
//	keyLock.Close(); // fourth step
//	CleanupStack::PopAndDestroy(); // keyLock	
//

}

// Key press happened
void CGuardKeyCapturer::RunL()
{
	if( iStatus == KErrNone ) 
	{
		// EEventKey received
		TWsEvent we;
		iWsSession.GetEvent( we );

		//if( we.Key()->iCode == KKeyCode ) 
		{
			if( we.Key()->iRepeats == 0 )
			{
			}
			else
			{
			}

			RAknKeyLock keyLock; // first step

			//	Start phone app
			_LIT(KPhoneAppPath, "\\system\\apps\\phone\\phone.app");
			{
				//	Open with the default/last known app
				CApaCommandLine * cmd = CApaCommandLine::NewL();        
				cmd->SetLibraryNameL( KPhoneAppPath );        
				cmd->SetCommandL( EApaCommandOpen );

				EikDll::StartAppL( *cmd );

				delete cmd;
			}

			//	Lock keyboard
			User::LeaveIfError(keyLock.Connect());  // second step
			CleanupClosePushL(keyLock);

			keyLock.EnableKeyLock(); // third step

			keyLock.Close(); // fourth step
			CleanupStack::PopAndDestroy(); // keyLock
		}
		//else 
		//	{
		//	//// This should never happen, but just to demonstrate how 
		//	//// it is possible to forward events to the default destination
		//	//TInt foregroundAppId = iWsSession.GetFocusWindowGroup();
		//	//iWsSession.SendEventToWindowGroup( foregroundAppId, we );
		//	}  // if iCode


		//if( iCaptureCounter == KNumberOfPressesToCapture ) 
		//	{
		//	// exit MainL() inner loop
		//	CActiveScheduler::Stop();
		//	}
		//else 
		{
			iWsSession.EventReady( &iStatus );
			SetActive();
		}  // if captured enough times
	}  // if iStatus
	else 
	{
		// Framework notified of some error
		/** @todo Handle error if required */
	}
}
// End of file

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -