libraries/ltkutils/src/keyinject.cpp
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // keyinject.cpp
       
     2 // 
       
     3 // Copyright (c) 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 // 
       
     9 // Initial Contributors:
       
    10 // Accenture - Initial contribution
       
    11 //
       
    12 #include <fshell/ltkutils.h>
       
    13 #include <e32event.h>
       
    14 #include <e32keys.h>
       
    15 #include <e32svr.h>
       
    16 
       
    17 EXPORT_C TInt LtkUtils::InjectRawKeyEvent(TInt aScanCode, TInt aModifiers, TInt /*aRepeatCount*/)
       
    18 	{
       
    19 	TInt err = KErrNone;
       
    20 	TRawEvent ev;
       
    21 
       
    22 	// Check for modifiers
       
    23 	if (!err && (aModifiers & EModifierCtrl))
       
    24 		{
       
    25 		ev.Set(TRawEvent::EKeyDown, EStdKeyLeftCtrl);
       
    26 		err = UserSvr::AddEvent(ev);
       
    27 		}
       
    28 	if (!err && (aModifiers & EModifierShift))
       
    29 		{
       
    30 		ev.Set(TRawEvent::EKeyDown, EStdKeyLeftShift);
       
    31 		err = UserSvr::AddEvent(ev);
       
    32 		}
       
    33 
       
    34 	// send the key down and up
       
    35 	if (!err)
       
    36 		{
       
    37 		ev.Set(TRawEvent::EKeyDown, aScanCode);
       
    38 		err = UserSvr::AddEvent(ev);
       
    39 		}
       
    40 	if (!err)
       
    41 		{
       
    42 		ev.Set(TRawEvent::EKeyUp, aScanCode);
       
    43 		err = UserSvr::AddEvent(ev);			
       
    44 		}
       
    45 
       
    46 	// generate repeats if necessary
       
    47 	/*
       
    48 	for (TInt i = 0; i < aRepeatCount; ii++)
       
    49 		{
       
    50 		ev.Set(TRawEvent::EKeyDown, aScanCode);
       
    51 		error = UserSvr::AddEvent(ev);
       
    52 		if (error == KErrNone)
       
    53 			{
       
    54 			ev.Set(TRawEvent::EKeyUp, sc);
       
    55 			error = UserSvr::AddEvent(ev);			
       
    56 			}
       
    57 		if (error != KErrNone)
       
    58 			break;			
       
    59 		}
       
    60 	*/
       
    61 
       
    62 	// Reset modifiers
       
    63 	if (!err && (aModifiers & EModifierShift))
       
    64 		{
       
    65 		ev.Set(TRawEvent::EKeyUp, EStdKeyLeftShift);
       
    66 		err = UserSvr::AddEvent(ev);
       
    67 		}
       
    68 	if (!err && (aModifiers & EModifierCtrl))
       
    69 		{
       
    70 		ev.Set(TRawEvent::EKeyUp, EStdKeyLeftCtrl);
       
    71 		err = UserSvr::AddEvent(ev);
       
    72 		}
       
    73 
       
    74 	return err;
       
    75 	}