How to force launch of VKB in CEikEdwin
Article Metadata
Tested with
Devices(s): S60
Compatibility
Platform(s): Symbian
Article
Keywords: CEikEdwin, CHelloWorldContainer
Created: chenziteng
(27 Sep 2009)
Last edited: hamishwillee
(13 Sep 2012)
Overview
Some developers would like the virtual keyboard to be displayed automatically, rather than requiring the user to first tap on the editor. The article describes how to force launch VKB in CEikEdwin by simulating a touch operation.
Solution
The solution of the specified problem is simulating a touch operation on the CEikEdwin object
void CHelloWorldContainer::LaunchVBKL()
{
if(iEdit1!=NULL)
{
TCursorSelection sel = iEdit1->Selection(); // remember the selection
const TInt KBorderWidth = 2;
const TInt KBorderHeight = 2;
TPointerEvent event;
event.iType = TPointerEvent::EButton1Down;
event.iParentPosition = iEdit1->PositionRelativeToScreen()+TPoint(KBorderWidth,KBorderHeight);
event.iPosition = iEdit1->Position()+TPoint(KBorderWidth,KBorderHeight);
iEdit1->HandlePointerEventL(event); // simulate a pointer down event
event.iType = TPointerEvent::EButton1Up;
iEdit1->HandlePointerEventL(event); // and then simulate a pointer up event to complete the touch operation
iEdit1->SetCursorPosL(sel.iAnchorPos, EFalse);
iEdit1->SetCursorPosL(sel.iCursorPos, ETrue); // restore the selection
}
}
Note that it is impossible to use the method to launch VKB right after the construction of the iEdit1 (in the ConstructL of the container), so if you'd like to show the VKB as soon as the container is constructed, you should run a AO and call the method in the RunL()
void CHelloWorldContainer::ConstructL(
const TRect& aRect,
const CCoeControl* aParent,
MEikCommandObserver* aCommandObserver )
{
...
// begin by chen
iAsyncCallBack = new(ELeave) CAsyncCallBack(TCallBack(AsyncCallBack, this), CActive::EPriorityStandard);
iAsyncCallBack->CallBack(); // AO that runs only once
// end by chen
}
...
TInt CHelloWorldContainer::AsyncCallBack(TAny* aParam)
{
if(aParam==NULL)
{
return KErrNoMemory;
}
CHelloWorldContainer* self = static_cast<CHelloWorldContainer*>(aParam);
TRAPD(err, self->LaunchVBKL());
return err;
}
Full example: HelloWorld(LaunchVKB).zip
Related articles (and discussions):


(no comments yet)