Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

How to send keypresses to another application

From Wiki
Jump to: navigation, search
Article Metadata
Article
Created: mgroeber9110 (02 Apr 2007)
Last edited: hamishwillee (25 Jul 2012)

This short code sample demonstrates sending the Shift+Ctrl+T keypress to System( ER5 Platform). On English machines this will have the effect of alternating the "Title position" setting between "Top of columns" and "Left of columns". Note that the caption of 'System' may be different on non-English devices, and it would therefore be better to use the target application's UID in a real-world product.

void CExampleAppUi::SendKeyTest()
 
{
TKeyEvent event;
event.iRepeats=0;
event.iScanCode=0;
event.iModifiers=EModifierCtrl | EModifierShift;
event.iCode=CTRL('t'); // defined in COEDEF.H
 
_LIT(KAppCaption,"System");
RWsSession& ws=iEikonEnv->WsSession();
TInt previous=0;
CApaWindowGroupName::FindByCaption(KAppCaption,ws,previous);
TApaTask task(ws);
task.SetWgId(previous);
if (!task.Exists())
User::Leave(KErrNotFound);task.BringToForeground(); // So we can see the results
task.SendKey(event);
}

Other keypress examples could include:

Ctrl+O:

      event.iModifiers=EModifierCtrl;
event.iCode=CTRL('o');

The letter "P":

      event.iModifiers=0;
event.iCode='P';


--

This page was last modified on 25 July 2012, at 09:19.
27 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.

×