Bring application to foreground with a keypress
Bring application to foreground with a keypress
From Forum Nokia Wiki
Inorder to capture the keys while you application under background you've to override CCoeAppUi::HandleWsEventL to your AppUi. With the use of RWindowGroup::CaptureKeyUpAndDowns() you can capture the keys from an application. Below is some sample code which will show you basically how to do it, you may find some additional bit of code which you may use.
The mmp file
CAPABILITY
SwEvent
The header file
/**
* To store the handle to the captured key.
*/
TInt iHashKeyHandle;
The cpp file
// -----------------------------------------------------------------------------
// CMyAppUi::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void
CMyAppUi::
ConstructL
()
{
BaseConstructL()
;
// ...
// set application as system application so that it will
// not be closed by system events
CEikonEnv::
Static
()
-
>
SetSystem(
ETrue )
;
// capture hash '#' key permanently
iHashKeyHandle =
CEikonEnv::
Static
()
-
>
RootWin()
.CaptureKeyUpAndDowns
(
EStdKeyHash, 0, 0)
;
// set application priority to foreground priority even if it goes to background
CEikonEnv::
Static
()
-
>
WsSession()
.ComputeMode
(
RWsSession::
EPriorityControlDisabled
)
;
// Make the application a high priority application
CEikonEnv::
Static
()
-
>
RootWin()
.EnableReceiptOfFocus
(
ETrue )
;
CEikonEnv::
Static
()
-
>
RootWin()
.SetOrdinalPosition
(
0, ECoeWinPriorityAlwaysAtFront)
;
}
// -----------------------------------------------------------------------------
// CMyAppUi::~CMyAppUi()
// Destructor.
// -----------------------------------------------------------------------------
//
CMyAppUi::
~CMyAppUi()
{
// Release the hanlde to the captured key.
CEikonEnv::
Static
()
-
>
RootWin()
.CancelCaptureKeyUpAndDowns
(
iHashKeyHandle)
;
// ...
}
// -----------------------------------------------------------------------------
// CMyAppUi::HandleForegroundEventL(TBool aForeground)
// Handles changes in keyboard focus when the application is brought to the
// foreground, or put into the background.
// -----------------------------------------------------------------------------
//
void
CMyAppUi::
HandleForegroundEventL
(
TBool aForeground)
{
// Make the application a high priority application
if
(
aForeground)
{
CEikonEnv::
Static
()
-
>
RootWin()
.SetOrdinalPosition
(
0, ECoeWinPriorityAlwaysAtFront)
;
}
}
// -----------------------------------------------------------------------------
// CMyAppUi::HandleWsEventL (const TWsEvent &aEvent, CCoeControl *aDestination)
// Handles events sent to the application by the window server.
// -----------------------------------------------------------------------------
//
void
CMyAppUi::
HandleWsEventL
(
const
TWsEvent &
aEvent, CCoeControl *
aDestination)
{
if
(
aEvent.Type
()
==
EEventKey ||
aEvent.Type
()
==
EEventKeyUp ||
aEvent.Type
()
==
EEventKeyDown ||
aEvent.Type
()
==
EEventKeyRepeat)
{
// This is for switching back to Application when Hash key is pressed
if
(
EStdKeyHash ==
aEvent.Key
()
-
>
iScanCode &&
EEventKey ==
aEvent.Type
())
{
TApaTask task(
iEikonEnv-
>
WsSession())
;
task.SetWgId
(
CEikonEnv::
Static
()
-
>
RootWin()
.Identifier
())
;
task.BringToForeground
()
;
return
;
}
}
CAknAppUi::
HandleWsEventL
(
aEvent, aDestination)
;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Pre-Query Samples
Validate the current query criteria or provide additional query criteria programmatically, just before sending the SELEC...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.
CAPABILITY
SwEvent
/**
* To store the handle to the captured key.
*/
TInt iHashKeyHandle;
// -----------------------------------------------------------------------------
// CMyAppUi::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void
CMyAppUi::
ConstructL
()
{
BaseConstructL()
;
// ...
// set application as system application so that it will
// not be closed by system events
CEikonEnv::
Static
()
-
>
SetSystem(
ETrue )
;
// capture hash '#' key permanently
iHashKeyHandle =
CEikonEnv::
Static
()
-
>
RootWin()
.CaptureKeyUpAndDowns
(
EStdKeyHash, 0, 0)
;
// set application priority to foreground priority even if it goes to background
CEikonEnv::
Static
()
-
>
WsSession()
.ComputeMode
(
RWsSession::
EPriorityControlDisabled
)
;
// Make the application a high priority application
CEikonEnv::
Static
()
-
>
RootWin()
.EnableReceiptOfFocus
(
ETrue )
;
CEikonEnv::
Static
()
-
>
RootWin()
.SetOrdinalPosition
(
0, ECoeWinPriorityAlwaysAtFront)
;
}
// -----------------------------------------------------------------------------
// CMyAppUi::~CMyAppUi()
// Destructor.
// -----------------------------------------------------------------------------
//
CMyAppUi::
~CMyAppUi()
{
// Release the hanlde to the captured key.
CEikonEnv::
Static
()
-
>
RootWin()
.CancelCaptureKeyUpAndDowns
(
iHashKeyHandle)
;
// ...
}
// -----------------------------------------------------------------------------
// CMyAppUi::HandleForegroundEventL(TBool aForeground)
// Handles changes in keyboard focus when the application is brought to the
// foreground, or put into the background.
// -----------------------------------------------------------------------------
//
void
CMyAppUi::
HandleForegroundEventL
(
TBool aForeground)
{
// Make the application a high priority application
if
(
aForeground)
{
CEikonEnv::
Static
()
-
>
RootWin()
.SetOrdinalPosition
(
0, ECoeWinPriorityAlwaysAtFront)
;
}
}
// -----------------------------------------------------------------------------
// CMyAppUi::HandleWsEventL (const TWsEvent &aEvent, CCoeControl *aDestination)
// Handles events sent to the application by the window server.
// -----------------------------------------------------------------------------
//
void
CMyAppUi::
HandleWsEventL
(
const
TWsEvent &
aEvent, CCoeControl *
aDestination)
{
if
(
aEvent.Type
()
==
EEventKey ||
aEvent.Type
()
==
EEventKeyUp ||
aEvent.Type
()
==
EEventKeyDown ||
aEvent.Type
()
==
EEventKeyRepeat)
{
// This is for switching back to Application when Hash key is pressed
if
(
EStdKeyHash ==
aEvent.Key
()
-
>
iScanCode &&
EEventKey ==
aEvent.Type
())
{
TApaTask task(
iEikonEnv-
>
WsSession())
;
task.SetWgId
(
CEikonEnv::
Static
()
-
>
RootWin()
.Identifier
())
;
task.BringToForeground
()
;
return
;
}
}
CAknAppUi::
HandleWsEventL
(
aEvent, aDestination)
;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Pre-Query SamplesValidate the current query criteria or provide additional query criteria programmatically, just before sending the SELEC...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.