×
Namespaces

Variants
Actions
Revision as of 08:04, 22 December 2011 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

强制打开CEikEdwin关联的虚拟键盘

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

代码示例
兼容于
文章
翻译:
chenziteng
最后由 hamishwillee 在 22 Dec 2011 编辑

概述

有些开发者希望虚拟键盘能够自动打开,而不是等用户第一次点击编辑框时打开。本文描述了如何通过模拟用户点击操作强制打开CEikEdwin关联的虚拟键盘。


方案

解决本问题的方案是模拟用户点击CEikEdwin的操作。


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
}
}

注意以上代码在(容器对象的ConstructL里)CEikEdwin对象刚刚构造完成时调用无效,因此如果想在容器对象构造完成后立即显示虚拟键盘的话,应该启动一个活动对象并在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;
}

完整的示例程序: HelloWorld(LaunchVKB).zip

相关文档 (和讨论):

VKB

How to force launch of VKB in FEP-aware custom control

"How to pop up virtual keyboard when view is shown"

This page was last modified on 22 December 2011, at 08:04.
73 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×