You Are Here:

Community: Wiki

This page was last modified on 18 June 2009, at 04:36.

Detecting keypad lock/unlock status

From Forum Nokia Wiki



Right now there is no observer/notifier pattern on the key lock API to notify the user of the keypad lock status, which means that to detect key lock activity the only choice is to keep polling the key lock api to check the status. This might not be a good idea as one can never be sure of the poll interval and it is not reliable either.

The following code snippet depicts a more reliable approach to detect the key pad lock status. Right now everytime the key pad is locked, the framework brings up a message like “Keypad Locked” when the keypad is locked and “Keypad unlocked” when it is unlocked, also if the user locks/unlocks the keypad manually then also the select dialog is popped up. The code below detects the popping up of those system dialogs which have a focus group id of either 3 or 9 and once they are detected it queries the key pad status, to see whats the status of the keypad.

Although the code is not 100% porting safe but it does the job right now till the time a notifier mechanism is implemented/published by Nokia.

Add following line to your .mmp file.

LIBRARY   ws32.lib apgrfx.lib

Add following lines in KeyPadLockStatusNotifier.h file.

#include <W32STD.H>
 
class MKeyPadLockStatusObserver
{
public:
/**
* Virtual function, implemented elsewhere
*/

virtual void KeyPadLockStatus(TBool aIslocked) = 0;
};
 
class CKeyPadLockStatusNotifier: public CActive
{
private:
CKeyPadLockStatusNotifier (MKeyPadLockStatusObserver & aKeyPadLockStatusObserver);
void ConstructL();
 
public:
static CKeyPadLockStatusNotifier * NewL(MKeyPadLockStatusObserver & aKeyPadLockStatusObserver);
~ CKeyPadLockStatusNotifier ();
void Start();
 
private:
// From CActive
void DoCancel();
void RunL();
TInt RunError(TInt aError);
 
private:
RWsSession iWs;
RWindowGroup iWindowGroup;
MKeyPadLockStatusObserver & iKeyPadockStatusObserver;
};

Add following lines in KeyPadLockStatusNotifier.cpp file.

#include <APGWGNAM.H>
#include <aknkeylock.h>
 
// User Include
#include "KeyPadLockStatusNotifier.h"
 
CKeyPadLockStatusNotifier::CKeyPadLockStatusNotifier (MKeyPadLockStatusObserver& aKeyPadLockStatusObserver)
:CActive(EPriorityIdle), iAppChangeObserver(aKeyPadLockStatusObserver
{
}
 
CKeyPadLockStatusNotifier* CKeyPadLockStatusNotifier::NewL(MKeyPadLockStatusObserver& aKeyPadLockStatusObserver)
{
CKeyPadLockStatusNotifier* self = new (ELeave)CKeyPadLockStatusNotifier(aKeyPadLockStatusObserver);
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(self);
return self;
}
 
void CKeyPadLockStatusNotifier::ConstructL()
{
CActiveScheduler::Add(this);
 
User::LeaveIfError(iWs.Connect());
 
// Windows Group
iWindowGroup = RWindowGroup(iWs);
User::LeaveIfError(iWindowGroup.Construct(reinterpret_cast<TUint32> (&iWindowGroup), EFalse));
iWindowGroup.SetOrdinalPosition(0, ECoeWinPriorityNeverAtFront);
iWindowGroup.EnableReceiptOfFocus(EFalse);
User::LeaveIfError(iWindowGroup.EnableFocusChangeEvents());
}
 
CKeyPadLockStatusNotifier::~CKeyPadLockStatusNotifier()
{
Cancel();
iWindowGroup.Close();
iWs.Close();
}
 
void CKeyPadLockStatusNotifier::Start()
{
iWs.EventReady(&iStatus);
SetActive();
}
 
void CKeyPadLockStatusNotifier::DoCancel()
{
iWs.EventReadyCancel();
}
 
void CKeyPadLockStatusNotifier::RunL()
{
// Get the event from the window server session iWs
TWsEvent wsEvent;
iWs.GetEvent(wsEvent);
// Get the event type: types are defined in TEventCode
switch (wsEvent.Type())
{
// Window-group related event types
case EEventFocusGroupChanged:
{
TInt wgid = iWs.GetFocusWindowGroup();
if(wgid == 3 || wgid == 9)
{
RAknKeylock2 keyLock;
TInt err;
TRAP(err, keyLock.Connect());
if(err == KErrNone)
{
TBool locked = keyLock.IsKeyLockEnabled();
iKeyPadockStatusObserver.KeyPadLockStatus(locked);
keyLock.Close();
}
}
}
break;
}
Start();
}
 
TInt CKeyPadLockStatusNotifier::RunError(TInt aError)
{
return KErrNone;
}

Add following lines in YourClass.h file.

class CYourClass:public CBase, public MKeyPadLockStatusObserver
{
public:
void KeyPadLockStatus(TBool aIslocked);
public:
CKeyPadLockStatusNotifier* iKeyPadLockStatusNotifier ;
};

Add following lines in YourClass.cpp file.

// Register for Ws Changes to be notified
iKeyPadLockStatusNotifier = CKeyPadLockStatusNotifier::NewL(*this);
 
void CYourClass:: KeyPadLockStatus (TBool aIslocked)
{
// Do something
}

The keypad lock status is returned to the user, where they can do the processing based on the status of the same.

Link

KIS001084 - Detecting keypad lock/unlock events not possible

KIS000831 - Querying Keypad status using GetIndicatorPayload() does not work with custom screensaver

Added by - Mayank on 18/06/2009

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fPortingE5fBlackBerryE5fStormE5fapplicationsE5fandE5fservicesE5ftoE5fS60E5f5thE5fE45ditionX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZseriesE5f60Q qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZuserE5ftagQSxs60X qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ
User Rating: qfnZuserE5FratingQNx4E2E0000X
RDF Facets: qfnZuserE5FtagQSxkeylockX