windowing/windowserver/nga/SERVER/EVENT.CPP
branchRCL_3
changeset 163 bbf46f59e123
parent 150 57c618273d5c
child 164 25ffed67c7ef
equal deleted inserted replaced
150:57c618273d5c 163:bbf46f59e123
    16 //
    16 //
    17 
    17 
    18 #include "EVENT.H"
    18 #include "EVENT.H"
    19 
    19 
    20 #include "W32STD.H"
    20 #include "W32STD.H"
       
    21 #include <e32uid.h>
    21 #include <hal.h>
    22 #include <hal.h>
    22 #include <w32adll.h>
    23 #include <w32adll.h>
    23 #include "W32CLICK.H"
    24 #include "W32CLICK.H"
    24 #include "server.h"
    25 #include "server.h"
    25 #include "windowgroup.h"
    26 #include "windowgroup.h"
    30 #include "inifile.h"
    31 #include "inifile.h"
    31 #include "password.h"
    32 #include "password.h"
    32 #include "pointer.h"
    33 #include "pointer.h"
    33 #include "debugbar.h"
    34 #include "debugbar.h"
    34 #include "advancedpointereventhelper.h"
    35 #include "advancedpointereventhelper.h"
    35 #include "Graphics/wsgraphicdrawerinternal.h"
    36 #include "graphics/wsgraphicdrawerinternal.h"
       
    37 #include "debughelper.h"
    36 
    38 
    37 GLREF_D CDebugLogBase *wsDebugLog;
    39 GLREF_D CDebugLogBase *wsDebugLog;
    38 
    40 
    39 GLREF_C void StateDump();
    41 GLREF_C void StateDump();
    40 GLREF_C void HeapDump();
    42 GLREF_C void HeapDump();
       
    43 
       
    44 _LIT(KDefaultKeyRouterPluginName, "keyrouter.dll");
       
    45 _LIT(KWSERVIniFileVarKeyRouterPlugin, "KEYROUTERPLUGIN");
    41 
    46 
    42 #define IMPOSSIBLE 0xFFFFFFFF
    47 #define IMPOSSIBLE 0xFFFFFFFF
    43 
    48 
    44 const TWsWinCmdCaptureKey ImpossibleKeyPress=
    49 const TWsWinCmdCaptureKey ImpossibleKeyPress=
    45 	{
    50 	{
   159 TEventRequestQueue TWindowServerEvent::iFocusChangedQueue;
   164 TEventRequestQueue TWindowServerEvent::iFocusChangedQueue;
   160 TEventRequestQueue TWindowServerEvent::iGroupListChangedQueue;
   165 TEventRequestQueue TWindowServerEvent::iGroupListChangedQueue;
   161 TEventRequestQueue TWindowServerEvent::iScreenDeviceChangedQueue;
   166 TEventRequestQueue TWindowServerEvent::iScreenDeviceChangedQueue;
   162 TTime TWindowServerEvent::iPrevOomMessageTime;
   167 TTime TWindowServerEvent::iPrevOomMessageTime;
   163 CCaptureKeys *TWindowServerEvent::iCaptureKeys;
   168 CCaptureKeys *TWindowServerEvent::iCaptureKeys;
       
   169 CKeyEventRouter* TWindowServerEvent::iKeyEventRouter;
       
   170 RLibrary TWindowServerEvent::iKeyEventRouterLibrary;
   164 CWsHotKey *TWindowServerEvent::iHotKeys;
   171 CWsHotKey *TWindowServerEvent::iHotKeys;
   165 TInt TWindowServerEvent::iModifierState;
   172 TInt TWindowServerEvent::iModifierState;
   166 CRawEventReceiver *TWindowServerEvent::iEventReceiver;
   173 CRawEventReceiver *TWindowServerEvent::iEventReceiver;
   167 RArray<TWindowServerEvent::TRawEventHandler> TWindowServerEvent::iEventHandlers;
   174 RArray<TWindowServerEvent::TRawEventHandler> TWindowServerEvent::iEventHandlers;
   168 CArrayFixFlat<SNotificationHandler> *TWindowServerEvent::iNotificationHandlers;
   175 CArrayFixFlat<SNotificationHandler> *TWindowServerEvent::iNotificationHandlers;
   171 RArray<TDrawerHandler>* TWindowServerEvent::iDrawerHandlers;
   178 RArray<TDrawerHandler>* TWindowServerEvent::iDrawerHandlers;
   172 RArray<TWsEventHandler> TWindowServerEvent::iWsEventHandlers;
   179 RArray<TWsEventHandler> TWindowServerEvent::iWsEventHandlers;
   173 TInt TWindowServerEvent::iEventHandlerCount=0;
   180 TInt TWindowServerEvent::iEventHandlerCount=0;
   174 TRepeatKey CKeyboardRepeat::iCurrentRepeat;
   181 TRepeatKey CKeyboardRepeat::iCurrentRepeat;
   175 TRepeatKey CKeyboardRepeat::iAlternateRepeat;
   182 TRepeatKey CKeyboardRepeat::iAlternateRepeat;
       
   183 TRepeatKey CKeyboardRepeat::iLongRepeat;
   176 TInt CKeyboardRepeat::iRepeatRollover=1;
   184 TInt CKeyboardRepeat::iRepeatRollover=1;
   177 CKeyboardRepeat::TRepeatType CKeyboardRepeat::iRepeating=ERepeatNone;
   185 CKeyboardRepeat::TRepeatType CKeyboardRepeat::iRepeating=ERepeatNone;
   178 CKeyboardRepeat *CKeyboardRepeat::iThis=NULL;
   186 CKeyboardRepeat *CKeyboardRepeat::iThis=NULL;
   179 TTimeIntervalMicroSeconds32 CKeyboardRepeat::iInitialTime;
   187 TTimeIntervalMicroSeconds32 CKeyboardRepeat::iInitialTime;
   180 TTimeIntervalMicroSeconds32 CKeyboardRepeat::iTime;
   188 TTimeIntervalMicroSeconds32 CKeyboardRepeat::iTime;
   181 CWsWindowGroup *CKeyboardRepeat::iFocus=NULL;
       
   182 TBool CKeyboardRepeat::iAlternateRepeatExists=EFalse;
   189 TBool CKeyboardRepeat::iAlternateRepeatExists=EFalse;
   183 CWsCaptureLongKey* CKeyboardRepeat::iLongCapture=NULL;
   190 CWsCaptureLongKey* CKeyboardRepeat::iLongCapture=NULL;
   184 
       
   185 TTimeIntervalMicroSeconds TWindowServerEvent::iPauseInterval;
       
   186 TTime TWindowServerEvent::iPauseStartTime;
       
   187 TInt TWindowServerEvent::iConfigationPauseTime = 0;
       
   188 
   191 
   189 
   192 
   190 void TWindowServerEvent::DeleteHotKeys()
   193 void TWindowServerEvent::DeleteHotKeys()
   191 	{
   194 	{
   192 	CWsHotKey *hotKey=iHotKeys;
   195 	CWsHotKey *hotKey=iHotKeys;
   201 
   204 
   202 void TWindowServerEvent::DeleteStatics()
   205 void TWindowServerEvent::DeleteStatics()
   203 	{
   206 	{
   204 	DeleteHotKeys();
   207 	DeleteHotKeys();
   205 	delete iCaptureKeys;
   208 	delete iCaptureKeys;
       
   209 	delete iKeyEventRouter;
       
   210 	iKeyEventRouterLibrary.Close();
   206 	CKeyboardRepeat::Destroy();
   211 	CKeyboardRepeat::Destroy();
   207 	delete iKeyTranslator;
   212 	delete iKeyTranslator;
   208 	delete iEventReceiver;
   213 	delete iEventReceiver;
   209 	iEventHandlers.Close();
   214 	iEventHandlers.Close();
   210 	delete iNotificationHandlers;
   215 	delete iNotificationHandlers;
   234 		TBuf<16> keyDataDllName;
   239 		TBuf<16> keyDataDllName;
   235 		keyDataDllName.Format(KLitKeyDataDllName,keyboardIndex);
   240 		keyDataDllName.Format(KLitKeyDataDllName,keyboardIndex);
   236 		iKeyTranslator->ChangeKeyData(keyDataDllName);
   241 		iKeyTranslator->ChangeKeyData(keyDataDllName);
   237 		}
   242 		}
   238 
   243 
       
   244 	// CCaptureKeys is no longer used but a dummy object is required for
       
   245 	// calls to CKeyTranslator::TranslateKey() until capture functionality
       
   246 	// has been removed from ektran.dll.
   239 	iCaptureKeys=new(ELeave) CCaptureKeys;
   247 	iCaptureKeys=new(ELeave) CCaptureKeys;
   240 	iCaptureKeys->Construct();
   248 	iCaptureKeys->Construct();
       
   249 
       
   250 	// Load the key event routing plug-in. The DLL name may be overridden
       
   251 	// by setting the keyword KEYROUTERPLUGIN in wsini.ini.
       
   252 	TPtrC pluginName(KDefaultKeyRouterPluginName);
       
   253 	WsIniFile->FindVar(KWSERVIniFileVarKeyRouterPlugin, pluginName);
       
   254 	const TUidType uidType(KDynamicLibraryUid, KKeyRouterPluginUid);
       
   255 	TInt err = iKeyEventRouterLibrary.Load(pluginName, uidType);
       
   256 
       
   257 	if (wsDebugLog)
       
   258 		{
       
   259 		TLogMessageText buf;
       
   260 
       
   261 		if (err == KErrNone)
       
   262 			{
       
   263 			_LIT(KLogLoadOk, "Loaded plugin '%S' UID3 0x%x");
       
   264 			const TFileName& pluginPathname = iKeyEventRouterLibrary.FileName();
       
   265 			const TUid uid3 = iKeyEventRouterLibrary.Type()[2];
       
   266 			buf.Format(KLogLoadOk, &pluginPathname, uid3.iUid);
       
   267 			}
       
   268 		else
       
   269 			{
       
   270 			_LIT(KLogLoadError, "Failed to load plugin '%S' (error %d)");
       
   271 			buf.Format(KLogLoadError, &pluginName, err);
       
   272 			}
       
   273 
       
   274 		wsDebugLog->MiscMessage(CDebugLogBase::ELogImportant, buf);
       
   275 		}
       
   276 
       
   277 	if (err != KErrNone)
       
   278 		{
       
   279 #ifdef _DEBUG
       
   280 		_LIT(KLoadError, "WServ: failed to load plugin '%S' (error %d)");
       
   281 		RDebug::Print(KLoadError, &pluginName, err);
       
   282 #endif
       
   283 		User::Leave(err);
       
   284 		}
       
   285 
       
   286 	// Create the key event router
       
   287 	typedef CKeyEventRouter* (*TCreateFunc)();
       
   288 	TCreateFunc newL = reinterpret_cast<TCreateFunc>(iKeyEventRouterLibrary.Lookup(1));
       
   289 	if (newL == NULL)
       
   290 		{
       
   291 		User::Leave(KErrNotFound);
       
   292 		}
       
   293 	iKeyEventRouter = (*newL)();
       
   294 
   241 	for (TInt index=0;index<TWindowServerEvent::ENumHotKeys;index++)
   295 	for (TInt index=0;index<TWindowServerEvent::ENumHotKeys;index++)
   242 		ConstructDefaultHotKeyL(index,DefaultHotKeys[index]);
   296 		ConstructDefaultHotKeyL(index,DefaultHotKeys[index]);
   243 	CKeyboardRepeat::NewL();
   297 	CKeyboardRepeat::NewL();
   244 	CKeyboardRepeat::SetRepeatTime(EDefaultInitialRepeatTime, EDefaultRepeatTime);
   298 	CKeyboardRepeat::SetRepeatTime(EDefaultInitialRepeatTime, EDefaultRepeatTime);
   245 	iEventHandlers=RArray<TRawEventHandler>(2);
   299 	iEventHandlers=RArray<TRawEventHandler>(2);
   246 	iNotificationHandlers=new(ELeave) CArrayFixFlat<SNotificationHandler>(2);
   300 	iNotificationHandlers=new(ELeave) CArrayFixFlat<SNotificationHandler>(2);
   247 	iDrawerHandlers = new(ELeave) RArray<TDrawerHandler>(4);
   301 	iDrawerHandlers = new(ELeave) RArray<TDrawerHandler>(4);
   248 	iPauseInterval = TTimeIntervalMicroSeconds(0);
       
   249    _LIT(KWSERVIniFileVarEventsPauseAfterRotation,"SUPPRESSEVENTSTIMEAFTERROTATION");
       
   250     WsIniFile->FindVar(KWSERVIniFileVarEventsPauseAfterRotation,iConfigationPauseTime);
       
   251 	}
   302 	}
   252 
   303 
   253 void TWindowServerEvent::LinkHotKey(CWsHotKey *aWsHotKey)
   304 void TWindowServerEvent::LinkHotKey(CWsHotKey *aWsHotKey)
   254 	{
   305 	{
   255 	aWsHotKey->SetLink(iHotKeys);
   306 	aWsHotKey->SetLink(iHotKeys);
   318 //
   369 //
   319 	TWsWinCmdCaptureKey captureKey;
   370 	TWsWinCmdCaptureKey captureKey;
   320 	captureKey.modifiers=aHotKey.modifiers;
   371 	captureKey.modifiers=aHotKey.modifiers;
   321 	captureKey.modifierMask=aHotKey.modifierMask;
   372 	captureKey.modifierMask=aHotKey.modifierMask;
   322 	captureKey.key=aHotKey.keycode;
   373 	captureKey.key=aHotKey.keycode;
       
   374 	captureKey.priority = 0;
   323 	hotKey->ConstructLD(captureKey);
   375 	hotKey->ConstructLD(captureKey);
   324 //
   376 //
   325 	LinkHotKey(hotKey);
   377 	LinkHotKey(hotKey);
   326 	}
   378 	}
   327 
   379 
   332 	WS_ASSERT_DEBUG(err==KErrNone, EWsPanicEventHandlerInconsistency);
   384 	WS_ASSERT_DEBUG(err==KErrNone, EWsPanicEventHandlerInconsistency);
   333 #else
   385 #else
   334 	iEventHandlers.AppendL(TRawEventHandler(aEventHandler, aAdvancedPointersEnabled));	//Shouldn't leave
   386 	iEventHandlers.AppendL(TRawEventHandler(aEventHandler, aAdvancedPointersEnabled));	//Shouldn't leave
   335 #endif
   387 #endif
   336 #ifdef LOG_WSERV_EVENTS
   388 #ifdef LOG_WSERV_EVENTS
   337 	RDebug::Printf("{EVNT}TWindowServerEvent::AddEventHandler Added Handler = %d Advanced Pointers Enabled = %d", iEventHandlers.Count(),aAdvancedPointersEnabled);
   389 	RDebug::Printf("_WSEVENT_POINTER: TWindowServerEvent::AddEventHandler Added handler = %d AdvancedPointerEnabled = %d", iEventHandlers.Count(),aAdvancedPointersEnabled);
   338 #endif
   390 #endif
   339 	}
   391 	}
   340 
   392 
   341 void TWindowServerEvent::RemoveEventHandler(const MEventHandler *aEventHandler)
   393 void TWindowServerEvent::RemoveEventHandler(const MEventHandler *aEventHandler)
   342 	{
   394 	{
   345 	for(ii=0;ii<count;++ii)
   397 	for(ii=0;ii<count;++ii)
   346 		{
   398 		{
   347 		if (iEventHandlers[ii].iEventHandler==aEventHandler)
   399 		if (iEventHandlers[ii].iEventHandler==aEventHandler)
   348 			{
   400 			{
   349 #ifdef LOG_WSERV_EVENTS
   401 #ifdef LOG_WSERV_EVENTS
   350 		    RDebug::Printf("{EVNT}TWindowServerEvent::RemoveEventHandler Removed Handler = %d",ii);
   402 		    RDebug::Printf("_WSEVENT_POINTER: TWindowServerEvent::RemoveEventHandler Removed handler = %d",ii);
   351 #endif
   403 #endif
   352 			if (iEventHandlerCount>0)  
   404 			if (iEventHandlerCount>0)  
   353 				{
   405 				{
   354 				iBinaryFlags |= ERemovedEventHandlerWhileProcessingRawEvents;
   406 				iBinaryFlags |= ERemovedEventHandlerWhileProcessingRawEvents;
   355 				iEventHandlers[ii].iEventHandler=NULL; // replace the Handler with null to keep size of the array
   407 				iEventHandlers[ii].iEventHandler=NULL; // replace the Handler with null to keep size of the array
   635 	CEventQueue *queue = aWsClient->EventQueue();
   687 	CEventQueue *queue = aWsClient->EventQueue();
   636 	TWsEvent event;
   688 	TWsEvent event;
   637 	event.SetType(EEventDisplayChanged);
   689 	event.SetType(EEventDisplayChanged);
   638 	event.SetTimeNow();
   690 	event.SetTimeNow();
   639 	
   691 	
   640 	// fill in the handle otherwise CONE will discard the notification
   692     // fill in the handle otherwise CONE will discard the notification
   641     CWsObjectIx* clientObjList = aWsClient->ObjectIndex();
   693     CWsObjectIx* clientObjList = aWsClient->ObjectIndex();
   642     const TWsObject* ptr=clientObjList->FirstObject();
   694     const TWsObject* ptr=clientObjList->FirstObject();
   643     const TWsObject* end=ptr+clientObjList->Length();
   695     const TWsObject* end=ptr+clientObjList->Length();
   644     while(++ptr<end)    // first one should always have a NULL object
   696     while(++ptr<end)    // first one should always have a NULL object
   645         {
   697         {
   664 	return ETrue;
   716 	return ETrue;
   665 	}
   717 	}
   666 
   718 
   667 void TWindowServerEvent::QueueKeyEvent(CWsWindowGroup *aWin, TWsEvent &aEvent, TWservEventPriorities aPriority)
   719 void TWindowServerEvent::QueueKeyEvent(CWsWindowGroup *aWin, TWsEvent &aEvent, TWservEventPriorities aPriority)
   668 	{
   720 	{
       
   721 #ifdef LOG_WSERV_EVENTS
       
   722     RDebug::Print(_L("_WSEVENT_KEY: TWindowServerEvent::QueueKeyEvent, Queuing event name %S for application read, window handle: %d"), &WsEventName(aEvent), CWsTop::FocusWindowGroup()->ClientHandle());
       
   723 #endif
   669 	aEvent.SetTimeNow();
   724 	aEvent.SetTimeNow();
   670 	aWin->EventQueue()->QueueEvent(aEvent, aPriority);
   725 	aWin->EventQueue()->QueueEvent(aEvent, aPriority);
   671 	}
   726 	}
   672 
   727 
   673 void TWindowServerEvent::QueueKeyPress(const TKeyData& aKey, TInt aScanCode, CWsWindowGroup* aRepeatFocus, TBool aCheckRepeat,TInt aRepeats)
   728 /**
       
   729 Process a key press event.
       
   730 
       
   731 This function is called for every input key event and uses the Key Event
       
   732 Routing plug-in to check for short and long key capture and determine the
       
   733 destination window group for the queued event(s).
       
   734 Window server hotkeys are also processed.
       
   735 Note that the key repeat timer is started here but the key repeat events
       
   736 generated by the timer go directly to QueueKeyPress().
       
   737 
       
   738 @param	aKeyEvent		Input key event
       
   739 @param	aCheckRepeat	Check for key repeat and long key capture
       
   740 @param	aRepeats		Repeat count
       
   741 */
       
   742 void TWindowServerEvent::ProcessKeyPress(const TKeyEvent& aKeyEvent, TBool aCheckRepeat, TInt aRepeats)
   674  	{
   743  	{
   675 	CWsWindowGroup* focusWin=CWsTop::FocusWindowGroup();
   744 	CWsWindowGroup* focusWin = CWsTop::FocusWindowGroup();
   676 	TWsEvent event;
   745 	TUid focusAppUid = focusWin ? TUid::Uid(focusWin->Client()->SecureId().iId) : KNullUid;
   677 	TKeyEvent& keyEvent=*event.Key();
   746 
   678 	keyEvent.iCode=aKey.iKeyCode;
   747 	// Route the key event and check for short key capture.
   679 	keyEvent.iScanCode=aScanCode;
   748 	// Note that the Key Routing plugin may translate or block key events.
   680 	keyEvent.iModifiers=aKey.iModifiers;
   749 	TKeyEventRouterInput input(ECaptureTypeKey, aKeyEvent, focusWin, focusAppUid);
   681 	keyEvent.iRepeats=aRepeats;
   750 	TKeyEventRouterOutput output;
   682 	if (!aRepeatFocus && CClick::IsHandler())
   751 
   683 		CClick::KeyEvent(EEventKey,keyEvent);
   752 #ifdef _DEBUG
   684 	CWsCaptureLongKey* longCapture=NULL;
   753 	// RouteKey() must not fail. Check for leaves in case the plug-in
   685 	if (aCheckRepeat)
   754 	// is badly behaved.
   686 		longCapture=CWsCaptureLongKey::CheckForCapture(aKey.iKeyCode, aKey.iModifiers);
   755 	TRAPD(err, iKeyEventRouter->RouteKey(input, output));
   687 	if (aKey.iIsCaptureKey)
   756 	WS_ASSERT_DEBUG(err == KErrNone, EWsPanicKeyEventRouterLeave);
   688 		{
   757 #else
   689 		if (aKey.iApp==NULL)	// Captured by Wserv itself
   758 	iKeyEventRouter->RouteKey(input, output);
       
   759 #endif
       
   760 
       
   761 	WS_ASSERT_DEBUG(output.iResult == ERouted || output.iResult == ECaptured || output.iResult == EConsumed, EWsPanicKeyEventRouterBadResult);
       
   762 
       
   763 	if (output.iResult == EConsumed)
       
   764 		{
       
   765 		focusWin = NULL;
       
   766 		}
       
   767 	else
       
   768 		{
       
   769 		focusWin = static_cast<CWsWindowGroup*>(output.iWindowGroup);
       
   770 		}
       
   771 	WS_ASSERT_DEBUG((focusWin == NULL || focusWin->Type() == WS_HANDLE_GROUP_WINDOW) && (output.iResult != ERouted || focusWin == CWsTop::FocusWindowGroup()), EWsPanicKeyEventRouterBadWindowGroup);
       
   772 
       
   773 	// Ensure that short event is not marked with EModifierLongKey
       
   774 	output.iKeyEvent.iModifiers &= ~EModifierLongKey;
       
   775 
       
   776 	// Generate key click unless the event is consumed. This is consistent
       
   777 	// with the behaviour when CKeyTranslator::TranslateKey() yields no
       
   778 	// translation for a particular scan code. (Click events for key up/down
       
   779 	// will still be generated by QueueKeyUpDown()). Note however that a long
       
   780 	// key press may still be captured even if the short event is consumed.
       
   781 	if (CClick::IsHandler() && output.iResult != EConsumed)
       
   782 		{
       
   783 		output.iKeyEvent.iRepeats = aRepeats;
       
   784 		CClick::KeyEvent(EEventKey, output.iKeyEvent);
       
   785 		}
       
   786 
       
   787 	if (output.iResult == ECaptured)
       
   788 		{
       
   789 		if (output.iWindowGroup == NULL)	// Captured by Wserv itself
   690 			{
   790 			{
   691 			_LIT(KWSERVDebugLogCapturedKey,"WSERV Captured Key");
   791 			_LIT(KWSERVDebugLogCapturedKey,"WSERV Captured Key");
   692 			CScreen* focusScreen=CWsTop::CurrentFocusScreen();
   792 			CScreen* focusScreen=CWsTop::CurrentFocusScreen();
   693 			TInt screenNo=focusScreen->ScreenNumber();
   793 			TInt screenNo=focusScreen->ScreenNumber();
   694 			
   794 			
   695 			if (wsDebugLog)
   795 			if (wsDebugLog)
   696 				wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogCapturedKey);
   796 				wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogCapturedKey);
   697 			CWsHotKey *hotKey=iHotKeys;
   797 			CWsHotKey *hotKey=iHotKeys;
   698 			while(hotKey)
   798 			while(hotKey)
   699 				{
   799 				{
   700 				if (hotKey->KeyHandle()==aKey.iHandle)
   800 				if (hotKey->KeyHandle() == reinterpret_cast<TInt>(output.iCaptureHandle))
   701 					{
   801 					{
   702 					switch(hotKey->HotKeyType())
   802 					switch(hotKey->HotKeyType())
   703 						{
   803 						{
   704 						case EHotKeyEnableLogging:
   804 						case EHotKeyEnableLogging:
   705 							CWsTop::EnableLogging();
   805 							CWsTop::EnableLogging();
   780 				hotKey=hotKey->iNext;
   880 				hotKey=hotKey->iNext;
   781 				}
   881 				}
   782 			WS_PANIC_ALWAYS(EWsPanicUnknownCaptureKey);
   882 			WS_PANIC_ALWAYS(EWsPanicUnknownCaptureKey);
   783 			return;
   883 			return;
   784 			}
   884 			}
   785 		focusWin=((CWsWindowGroup *)aKey.iApp);
   885 
   786 		_LIT(KWSERVDebugLogKeyCapturedByApp,"Key captured by app %d");
   886 		_LIT(KWSERVDebugLogKeyCapturedByApp,"Key captured by app %d");
   787 		if (wsDebugLog)
   887 		if (wsDebugLog)
   788 			wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogKeyCapturedByApp,focusWin->Identifier());
   888 			wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogKeyCapturedByApp,focusWin->Identifier());
   789 		if (CWsPassword::PasswordModeActive() && focusWin!=CWsPassword::PasswordWindow()->WinGroup())
   889 		if (CWsPassword::PasswordModeActive() && focusWin!=CWsPassword::PasswordWindow()->WinGroup())
   790 			return;
   890 			return;
   791 		}
   891 		}
   792 	if (aRepeatFocus && aRepeatFocus!=focusWin)
   892 
       
   893 	CWsCaptureLongKey* longCapture = NULL;
       
   894 	TKeyEventRouterOutput longOutput;
       
   895 	if (aCheckRepeat)
       
   896 		{
       
   897 		// Check for long key capture.
       
   898 		// Note that a long key event can only result from capture, there is
       
   899 		// no default detection or routing of long events.
       
   900 		input.iType = ECaptureTypeLongKey;
       
   901 #ifdef _DEBUG
       
   902 		TRAPD(err, iKeyEventRouter->RouteKey(input, longOutput));
       
   903 		WS_ASSERT_DEBUG(err == KErrNone, EWsPanicKeyEventRouterLeave);
       
   904 #else
       
   905 		iKeyEventRouter->RouteKey(input, longOutput);
       
   906 #endif
       
   907 
       
   908 		if (longOutput.iResult == ECaptured)
       
   909 			{
       
   910 			longCapture = static_cast<CWsCaptureLongKey*>(longOutput.iCaptureHandle);
       
   911 
       
   912 			// Mark long key events with EModifierLongKey so that applications
       
   913 			// can easily distinguish short and long events.
       
   914 			longOutput.iKeyEvent.iModifiers |= EModifierLongKey;
       
   915 
       
   916 			// Start timer to detect long key press
       
   917 			CKeyboardRepeat::StartRepeat(aKeyEvent.iScanCode, output, &longOutput);
       
   918 			}
       
   919 		else if (output.iResult != EConsumed && output.iKeyEvent.iModifiers & EModifierAutorepeatable)
       
   920 			{
       
   921 			// Start timer for key repeat
       
   922 			CKeyboardRepeat::StartRepeat(aKeyEvent.iScanCode, output, NULL);
       
   923 			}
       
   924 		}
       
   925 
       
   926 	// Queue the short event
       
   927 	if (!longCapture || longCapture->iFlags & ELongCaptureShortEventImmediately)
       
   928 		{
       
   929 		QueueKeyPress(output, EFalse, aRepeats);
       
   930 		}
       
   931 	}
       
   932 
       
   933 /**
       
   934 Queue a key press event.
       
   935 
       
   936 This function is called for each key event produced by ProcessKeyPress(),
       
   937 for every key repeat and long key event generated by the timer and also for
       
   938 delayed short key events from KeyUp().
       
   939 
       
   940 @param	aOutput			Output key event from routing plug-in
       
   941 @param	aIsRepeat		Event is due to key repeat
       
   942 @param	aRepeats		Repeat count
       
   943 */
       
   944 void TWindowServerEvent::QueueKeyPress(const TKeyEventRouterOutput& aOutput, TBool aIsRepeat, TInt aRepeats)
       
   945  	{
       
   946 	if (aOutput.iResult == EConsumed)
       
   947 		{
       
   948 		// Don't deliver this key
       
   949 		return;
       
   950 		}
       
   951 
       
   952 	TWsEvent event;
       
   953 	TKeyEvent& keyEvent = *event.Key();
       
   954 	keyEvent = aOutput.iKeyEvent;
       
   955 	keyEvent.iRepeats = aRepeats;
       
   956 
       
   957 	CWsWindowGroup* focusWin = static_cast<CWsWindowGroup*>(aOutput.iWindowGroup);
       
   958 	WS_ASSERT_DEBUG(focusWin == NULL || focusWin->Type() == WS_HANDLE_GROUP_WINDOW, EWsPanicKeyEventRouterBadWindowGroup);
       
   959 
       
   960 	if (aIsRepeat && aOutput.iResult != ECaptured && focusWin != CWsTop::FocusWindowGroup())
   793 		CKeyboardRepeat::CancelRepeat(NULL);		// Repeat is going to different window so cancel it and don't deliver this key
   961 		CKeyboardRepeat::CancelRepeat(NULL);		// Repeat is going to different window so cancel it and don't deliver this key
   794 	else if (focusWin!=NULL && focusWin->CheckForPriorityKey(aKey,aScanCode)==EFalse)
   962 	else if (focusWin != NULL && focusWin->CheckForPriorityKey(keyEvent) == EFalse)
   795 		{
   963 		{
   796 		if (longCapture || (aCheckRepeat && !aRepeatFocus && aKey.iModifiers&EModifierAutorepeatable))
       
   797 			{
       
   798 			if (CKeyboardRepeat::StartRepeat(aKey,aScanCode,focusWin,longCapture))
       
   799 				return;
       
   800 			}
       
   801 		event.SetType(EEventKey);
   964 		event.SetType(EEventKey);
   802 		event.SetHandle(focusWin->ClientHandle());
   965 		event.SetHandle(focusWin->ClientHandle());
   803 		if (aRepeats!=0)
   966 		if (aRepeats!=0)
   804 			{
   967 			{
   805 			CEventQueue* queue=focusWin->EventQueue();
   968 			CEventQueue* queue=focusWin->EventQueue();
   806 			queue->Wait();
   969 			queue->Wait();
   807 			const TWsEvent* prev=queue->PeekLastEvent();
   970 			const TWsEvent* prev=queue->PeekLastEvent();
   808 			if (prev!=NULL && prev->Type()==EEventKey && prev->Key()->iRepeats>0)
   971 			if (prev != NULL && prev->Type() == EEventKey && prev->Key()->iRepeats > 0 && prev->Key()->iCode == keyEvent.iCode)
   809 				{
   972 				{
   810 				event= *prev;
   973 				prev->Key()->iRepeats += aRepeats;
   811 				event.Key()->iRepeats+=aRepeats;
       
   812 				queue->UpdateLastEvent(event);
       
   813 				queue->Signal();
   974 				queue->Signal();
   814 				if (CClick::IsHandler())
   975 				if (CClick::IsHandler())
   815 					CClick::KeyEvent(EEventKeyRepeat,*event.Key());
   976 					CClick::KeyEvent(EEventKeyRepeat, *prev->Key());
   816 				return;
   977 				return;
   817 				}
   978 				}
   818 			queue->Signal();
   979 			queue->Signal();
   819 			event.Key()->iRepeats=aRepeats;
       
   820 			if (CClick::IsHandler())
   980 			if (CClick::IsHandler())
   821 				CClick::KeyEvent(EEventKeyRepeat,keyEvent);
   981 				CClick::KeyEvent(EEventKeyRepeat,keyEvent);
   822 			}
   982 			}
   823 		QueueKeyEvent(focusWin, event, EEventPriorityLow);
   983 		QueueKeyEvent(focusWin, event, EEventPriorityLow);
   824 		}
   984 		}
   825 	}
   985 	}
   826 
   986 
       
   987 /**
       
   988 Queue a key up/down event.
       
   989 
       
   990 @param	aRawEvent		Raw event
       
   991 */
   827 void TWindowServerEvent::QueueKeyUpDown(const TRawEvent &aRawEvent)
   992 void TWindowServerEvent::QueueKeyUpDown(const TRawEvent &aRawEvent)
   828  	{
   993  	{
   829 	CWsWindowGroup *focusWin=CWsCaptureKeyUpsAndDowns::CheckForCapture(aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE, iModifierState);
   994 #ifdef LOG_WSERV_EVENTS
   830 	if (!focusWin)	// If not captured
   995     RDebug::Print(_L("_WSEVENT_KEY: TWindowServerEvent::QueueKeyUpDown, Event Name: %S, Scan code: %d"), &RawEventName(aRawEvent), aRawEvent.ScanCode());
   831 		focusWin=CWsTop::FocusWindowGroup();
   996 #endif
   832 	TWsEvent event;
   997 	TEventCode type = aRawEvent.Type() == TRawEvent::EKeyUp ? EEventKeyUp : EEventKeyDown;
   833 	TEventCode type=aRawEvent.Type()==TRawEvent::EKeyUp ? EEventKeyUp : EEventKeyDown;
   998 
   834 	event.Key()->iCode=0;
   999 	// Check for key up/down capture
       
  1000 	TKeyEvent keyEvent;
       
  1001 	keyEvent.iScanCode = aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE;
       
  1002 #if defined(__WINS__)
       
  1003 	keyEvent.iCode = __WINS_CHARCODE(aRawEvent.ScanCode());
       
  1004 #else
       
  1005 	keyEvent.iCode = 0;
       
  1006 #endif
       
  1007 	keyEvent.iModifiers = iModifierState;
       
  1008 	keyEvent.iRepeats = 0;
       
  1009 
       
  1010 	CWsWindowGroup* focusWin = CWsTop::FocusWindowGroup();
       
  1011 	TUid focusAppUid = focusWin ? TUid::Uid(focusWin->Client()->SecureId().iId) : KNullUid;
       
  1012 
       
  1013 	TKeyEventRouterInput input(ECaptureTypeKeyUpDown, keyEvent, focusWin, focusAppUid);
       
  1014 	TKeyEventRouterOutput output;
       
  1015 #ifdef _DEBUG
       
  1016 	TRAPD(err, iKeyEventRouter->RouteKey(input, output));
       
  1017 	WS_ASSERT_DEBUG(err == KErrNone, EWsPanicKeyEventRouterLeave);
       
  1018 #else
       
  1019 	iKeyEventRouter->RouteKey(input, output);
       
  1020 #endif
       
  1021 
       
  1022 	if (output.iResult == EConsumed)
       
  1023 		{
       
  1024 		// Don't deliver this key. A key click is still generated for the
       
  1025 		// input event.
       
  1026 		if (CClick::IsHandler())
       
  1027 			{
       
  1028 			CClick::KeyEvent(type, keyEvent);
       
  1029 			}
       
  1030 		return;
       
  1031 		}
       
  1032 	WS_ASSERT_DEBUG(output.iResult == ERouted || output.iResult == ECaptured, EWsPanicKeyEventRouterBadResult);
       
  1033 
       
  1034 	focusWin = static_cast<CWsWindowGroup*>(output.iWindowGroup);
       
  1035 	WS_ASSERT_DEBUG((focusWin == NULL || focusWin->Type() == WS_HANDLE_GROUP_WINDOW) && (output.iResult != ERouted || focusWin == CWsTop::FocusWindowGroup()), EWsPanicKeyEventRouterBadWindowGroup);
   835 #if defined(__WINS__)
  1036 #if defined(__WINS__)
   836 	if (focusWin && !focusWin->WsOwner()->RemoveKeyCode())
  1037 	if (focusWin && !focusWin->WsOwner()->RemoveKeyCode())
   837 		event.Key()->iScanCode=aRawEvent.ScanCode();
  1038 		{
   838 	else
  1039 		// Restore WINS character code
   839 #endif
  1040 		output.iKeyEvent.iScanCode |= output.iKeyEvent.iCode;
   840 	event.Key()->iScanCode=aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE;
  1041 		}
   841 	event.Key()->iModifiers=iModifierState;
  1042 	output.iKeyEvent.iCode = 0;
   842 	event.Key()->iRepeats=0;
  1043 #endif
       
  1044 
       
  1045 	output.iKeyEvent.iRepeats = 0;
   843 	if (CClick::IsHandler())
  1046 	if (CClick::IsHandler())
   844 		CClick::KeyEvent(type,*event.Key());
  1047 		{
       
  1048 		CClick::KeyEvent(type, output.iKeyEvent);
       
  1049 		}
       
  1050 
       
  1051 	TWsEvent event;
       
  1052 	*event.Key() = output.iKeyEvent;
   845 	if (focusWin!=NULL)
  1053 	if (focusWin!=NULL)
   846 		{
  1054 		{
   847 		event.SetType(type);
  1055 		event.SetType(type);
   848 		event.SetHandle(focusWin->ClientHandle());
  1056 		event.SetHandle(focusWin->ClientHandle());
   849 		QueueKeyEvent(focusWin, event, EEventPriorityHigh);
  1057 		QueueKeyEvent(focusWin, event, EEventPriorityHigh);
   949 			break;
  1157 			break;
   950 		}
  1158 		}
   951 	}
  1159 	}
   952 
  1160 
   953 /*
  1161 /*
   954  Pause in processing all raw pointer and key events (except processing by anim's dll plug-ins).
  1162 Process a raw event
   955  All events will be ignored except for anim's dll plug-ins.
  1163 
   956  Pause prevents pointer events to come to wrong windows due to screen width and size changes. 
  1164 @param	aRawEvent	Raw event
   957  @param aPauseInterval - the pause interval in microseconds.
       
   958 */
  1165 */
   959 void TWindowServerEvent::PauseProcessRawEvents(TInt aPauseInterval)
       
   960     {
       
   961     iPauseInterval = TTimeIntervalMicroSeconds(aPauseInterval);
       
   962     iPauseStartTime.UniversalTime();
       
   963 #ifdef LOG_WSERV_EVENTS
       
   964      RDebug::Printf("{EVNT}TWindowServerEvent::PauseProcessRawEvents aPauseInterval = %d",aPauseInterval);
       
   965 #endif
       
   966     }
       
   967 
       
   968 void TWindowServerEvent::ProcessRawEvent(const TRawEvent& aRawEvent)
  1166 void TWindowServerEvent::ProcessRawEvent(const TRawEvent& aRawEvent)
   969 //
  1167 //
   970 // Event has completed.
  1168 // Event has completed.
   971 //
  1169 //
   972 	{
  1170 	{
   973     TBool pauseProcessEvents = EFalse;
       
   974     //Check if the pause in processing all raw pointer and key events was set.
       
   975     if(iPauseInterval.Int64() > 0)
       
   976         {
       
   977         TTime current;
       
   978         current.UniversalTime();
       
   979         TTimeIntervalMicroSeconds interval = current.MicroSecondsFrom(
       
   980                 iPauseStartTime);
       
   981         if ((interval.Int64() > iPauseInterval.Int64()) || (interval.Int64() < 0))
       
   982             {
       
   983             iPauseInterval = TTimeIntervalMicroSeconds(0);
       
   984             }
       
   985         else
       
   986             {
       
   987             // Set flag ignore of processing all raw events (except processing by anim's dll plug-ins)
       
   988             // All events will be ignored except for anim's dll plug-ins.
       
   989             pauseProcessEvents = ETrue;
       
   990             }
       
   991         }
       
   992 
       
   993 #ifdef LOG_WSERV_EVENTS
       
   994     if(pauseProcessEvents)
       
   995         RDebug::Printf("{EVNT}TWindowServerEvent::ProcessRawEvent Processing of Raw Event - DISABLED");
       
   996     else
       
   997         RDebug::Printf("{EVNT}TWindowServerEvent::ProcessRawEvent Processing of Raw Event - ENABLED");
       
   998 #endif
       
   999     
       
  1000 	TRawEvent::TType eventType = aRawEvent.Type();
  1171 	TRawEvent::TType eventType = aRawEvent.Type();
  1001 	TBool isPointerEvent = TWsPointer::IsPointerEventType(eventType);
  1172 	TBool isPointerEvent = TWsPointer::IsPointerEventType(eventType);
  1002 	if (isPointerEvent)
  1173 	if (isPointerEvent)
  1003 		{
  1174 		{
  1004 #ifdef LOG_WSERV_EVENTS
  1175 #ifdef LOG_WSERV_EVENTS
  1005         RDebug::Printf("{EVNT}TWindowServerEvent::ProcessRawEvent EventType = 0x0%X PointerNumber = %d PrimaryPointerNumber = %d XY(%d,%d)", 
  1176         RDebug::Print(_L("_WSEVENT_POINTER: TWindowServerEvent::ProcessRawEvent EventName = %S PointerNumber = %d PrimaryPointerNumber = %d Coordinates = ( %d, %d )"), 
  1006                 aRawEvent.Type(),aRawEvent.PointerNumber(),TWsPointer::PrimaryPointer(),aRawEvent.Pos().iX,aRawEvent.Pos().iY); 
  1177                 &RawEventName(aRawEvent),aRawEvent.PointerNumber(),TWsPointer::PrimaryPointer(),aRawEvent.Pos().iX,aRawEvent.Pos().iY); 
  1007 #endif
  1178 #endif
  1008         TWsPointer::UpdatePrimaryPointer(aRawEvent);
  1179         TWsPointer::UpdatePrimaryPointer(aRawEvent);
  1009 		}
  1180 		}
  1010 	TInt count=iEventHandlers.Count();
  1181 	TInt count=iEventHandlers.Count();
  1011 	TInt ii;
  1182 	TInt ii;
  1020 			 aRawEvent.PointerNumber() == TWsPointer::PrimaryPointer()) &&
  1191 			 aRawEvent.PointerNumber() == TWsPointer::PrimaryPointer()) &&
  1021 			handler.iEventHandler->OfferRawEvent(aRawEvent))
  1192 			handler.iEventHandler->OfferRawEvent(aRawEvent))
  1022 			{
  1193 			{
  1023 			if (CClick::IsHandler())
  1194 			if (CClick::IsHandler())
  1024 				{
  1195 				{
       
  1196 #ifdef LOG_WSERV_EVENTS
       
  1197 				RDebug::Print(_L("_WSEVENT_KEY: Send event %S for Key Click"), &RawEventName(aRawEvent));
       
  1198 #endif
  1025 				SendEventToKeyClick(aRawEvent);
  1199 				SendEventToKeyClick(aRawEvent);
  1026 				}
  1200 				}
  1027 			eventHandled = ETrue;
  1201 			eventHandled = ETrue;
  1028 #ifdef LOG_WSERV_EVENTS
  1202 #ifdef LOG_WSERV_EVENTS
  1029             RDebug::Printf("{EVNT}TWindowServerEvent::ProcessRawEvent Event Consumed by Handler No = %d Advanced Pointers Enabled = %d",ii,handler.iAdvancedPointersEnabled);
  1203             RDebug::Printf("_WSEVENT_POINTER: TWindowServerEvent::ProcessRawEvent Event Consumed by ANIM.dll Handler No = %d Advanced Pointer Enabled = %d",ii,handler.iAdvancedPointersEnabled);
  1030 #endif
  1204 #endif
  1031 			break;
  1205 			break;
  1032 			}
  1206 			}
  1033 		}
  1207 		}
  1034 	if (--iEventHandlerCount == 0)
  1208 	if (--iEventHandlerCount == 0)
  1040 				{
  1214 				{
  1041 				if (iEventHandlers[ii].iEventHandler==NULL) iEventHandlers.Remove(ii);
  1215 				if (iEventHandlers[ii].iEventHandler==NULL) iEventHandlers.Remove(ii);
  1042 				}
  1216 				}
  1043 			}
  1217 			}
  1044 		}
  1218 		}
  1045 	if ((eventHandled)||(pauseProcessEvents))
  1219 	if (eventHandled)
  1046 		{
  1220 		{
       
  1221 #ifdef LOG_WSERV_EVENTS
       
  1222 		RDebug::Printf("_WSEVENT: Event is already handled by anim dll not by window server");
       
  1223 		// This is to determine when we press the power button which bring power dialog
       
  1224 		// whether it is a pointer event or key event
       
  1225 		// Also when we plugin the charging cable this is to determine whether it is a pointer event or key event
       
  1226 		RDebug::Print(_L("_WSEVENT: RawEvent Name = %S"), &RawEventName(aRawEvent));
       
  1227 #endif
  1047 		if (isPointerEvent)
  1228 		if (isPointerEvent)
  1048 			{ 
  1229 			{
       
  1230 #ifdef LOG_WSERV_EVENTS
       
  1231 			RDebug::Printf("_WSEVENT_POINTER: TWindowServerEvent::ProcessRawEvent Pointer Number= %d  State = %x XY(%d,%d)",TWsPointer::iPointers[0].iNumber,TWsPointer::iPointers[0].iState,TWsPointer::iPointers[0].iPos.iX,TWsPointer::iPointers[0].iPos.iY);
       
  1232 		    RDebug::Printf("_WSEVENT_POINTER: TWindowServerEvent::ProcessRawEvent Pointer Number= %d  State = %x XY(%d,%d)",TWsPointer::iPointers[1].iNumber,TWsPointer::iPointers[1].iState,TWsPointer::iPointers[1].iPos.iX,TWsPointer::iPointers[1].iPos.iY);
       
  1233 #endif
  1049               //Prevention of the phone pointer event "dead lock". 
  1234               //Prevention of the phone pointer event "dead lock". 
  1050               TPointerEvent::TType type;
  1235               TPointerEvent::TType type;
  1051               TBool handled = ETrue;
  1236               TBool handled = ETrue;
  1052               GetPointerEvent(type, aRawEvent, handled);
  1237               GetPointerEvent(type, aRawEvent, handled);
  1053               switch(type)
  1238               switch(type)
  1066                       TWsPointer::iPointers[aRawEvent.PointerNumber()].iState = TWsPointer::EPointerStateOutOfRange;
  1251                       TWsPointer::iPointers[aRawEvent.PointerNumber()].iState = TWsPointer::EPointerStateOutOfRange;
  1067                       break;
  1252                       break;
  1068                       default:
  1253                       default:
  1069                       break;
  1254                       break;
  1070                   }
  1255                   }
  1071 #ifdef LOG_WSERV_EVENTS
  1256 			}
  1072             RDebug::Printf("{EVNT}TWindowServerEvent::ProcessRawEvent Pointer Number= %d  State = %x XY(%d,%d)",TWsPointer::iPointers[0].iNumber,TWsPointer::iPointers[0].iState,TWsPointer::iPointers[0].iPos.iX,TWsPointer::iPointers[0].iPos.iY);
       
  1073             RDebug::Printf("{EVNT}TWindowServerEvent::ProcessRawEvent Pointer Number= %d  State = %x XY(%d,%d)",TWsPointer::iPointers[1].iNumber,TWsPointer::iPointers[1].iState,TWsPointer::iPointers[1].iPos.iX,TWsPointer::iPointers[1].iPos.iY);
       
  1074 #endif
       
  1075 			}
       
  1076 #ifdef LOG_WSERV_EVENTS
       
  1077 		if(pauseProcessEvents)
       
  1078 		    RDebug::Printf("{EVNT}TWindowServerEvent::ProcessRawEvent Further Processing of Raw Event - IGNORED");
       
  1079 #endif
       
  1080 		return;
  1257 		return;
  1081 		}
  1258 		}
  1082 	
  1259 	
  1083 	switch(eventType)
  1260 	switch(eventType)
  1084 		{
  1261 		{
  1125 			CWsTop::WindowServer()->AnimationScheduler()->OnActive();
  1302 			CWsTop::WindowServer()->AnimationScheduler()->OnActive();
  1126 #endif
  1303 #endif
  1127 			break;
  1304 			break;
  1128 		case TRawEvent::EKeyDown:
  1305 		case TRawEvent::EKeyDown:
  1129 			{
  1306 			{
       
  1307 #ifdef LOG_WSERV_EVENTS
       
  1308 			RDebug::Printf("_WSEVENT_KEY: TRawEvent::EKeyDown");
       
  1309 #endif
  1130 			_LIT(KWSERVDebugLogKeyDownArrival,"Key down arrives %d");
  1310 			_LIT(KWSERVDebugLogKeyDownArrival,"Key down arrives %d");
  1131 			CScreen* screen = CWsTop::Screen();
  1311 			CScreen* screen = CWsTop::Screen();
  1132 			WS_ASSERT_ALWAYS(screen, EWsPanicNoScreen);
  1312 			WS_ASSERT_ALWAYS(screen, EWsPanicNoScreen);
  1133 			if(CDebugBar* dbg = screen->DebugBar())
  1313 			if(CDebugBar* dbg = screen->DebugBar())
  1134 				dbg->OnKeyEvent();
  1314 				dbg->OnKeyEvent();
  1135 			if (wsDebugLog)
  1315 			if (wsDebugLog)
  1136 				wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogKeyDownArrival,aRawEvent.ScanCode());
  1316 				wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogKeyDownArrival,aRawEvent.ScanCode());
  1137 			CKeyboardRepeat::KeyDown();
  1317 			CKeyboardRepeat::KeyDown();
  1138 			TKeyData keyData;
  1318 			TKeyData keyData;
       
  1319 			// Note iCaptureKeys is needed as dummy arg only. Key capture is
       
  1320 			// now handled in ProcessKeyPress().
  1139 			TBool translated=iKeyTranslator->TranslateKey(aRawEvent.ScanCode(), EFalse,*iCaptureKeys,keyData);
  1321 			TBool translated=iKeyTranslator->TranslateKey(aRawEvent.ScanCode(), EFalse,*iCaptureKeys,keyData);
  1140 			ProcessModifierChanges();
  1322 			ProcessModifierChanges();
  1141 			QueueKeyUpDown(aRawEvent);
  1323 			QueueKeyUpDown(aRawEvent);
  1142 			if (translated)
  1324 			if (translated)
  1143 				QueueKeyPress(keyData,aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE,NULL,ETrue,0);
  1325 				{
       
  1326 				TKeyEvent keyEvent;
       
  1327 				keyEvent.iScanCode = aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE;
       
  1328 				keyEvent.iCode = keyData.iKeyCode;
       
  1329 				keyEvent.iModifiers = keyData.iModifiers;
       
  1330 				ProcessKeyPress(keyEvent, ETrue, 0);
       
  1331 				}
  1144 			}
  1332 			}
  1145 			break;
  1333 			break;
  1146 		case TRawEvent::EKeyUp:
  1334 		case TRawEvent::EKeyUp:
  1147 			{
  1335 			{
       
  1336 #ifdef LOG_WSERV_EVENTS
       
  1337 			RDebug::Printf("_WSEVENT_KEY: TRawEvent::EKeyUp");
       
  1338 #endif
  1148 			_LIT(KWSERVDebugLogKeyUpArrival,"Key up arrives %d");
  1339 			_LIT(KWSERVDebugLogKeyUpArrival,"Key up arrives %d");
  1149 			CScreen* screen = CWsTop::Screen();
  1340 			CScreen* screen = CWsTop::Screen();
  1150 			WS_ASSERT_ALWAYS(screen, EWsPanicNoScreen);
  1341 			WS_ASSERT_ALWAYS(screen, EWsPanicNoScreen);
  1151 			if(CDebugBar* dbg = screen->DebugBar())
  1342 			if(CDebugBar* dbg = screen->DebugBar())
  1152 				dbg->OnKeyEvent();
  1343 				dbg->OnKeyEvent();
  1158 			ProcessModifierChanges();
  1349 			ProcessModifierChanges();
  1159 			QueueKeyUpDown(aRawEvent);
  1350 			QueueKeyUpDown(aRawEvent);
  1160 			if (translated)
  1351 			if (translated)
  1161 				{
  1352 				{
  1162 				CKeyboardRepeat::CancelRepeat(NULL);
  1353 				CKeyboardRepeat::CancelRepeat(NULL);
  1163 				QueueKeyPress(keyData,aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE,NULL,EFalse,0);
  1354 				TKeyEvent keyEvent;
       
  1355 				keyEvent.iScanCode = aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE;
       
  1356 				keyEvent.iCode = keyData.iKeyCode;
       
  1357 				keyEvent.iModifiers = keyData.iModifiers;
       
  1358 				ProcessKeyPress(keyEvent, EFalse, 0);
  1164 				}
  1359 				}
  1165 			}
  1360 			}
  1166 			break;
  1361 			break;
  1167 		case TRawEvent::EButton1Down:
  1362 		case TRawEvent::EButton1Down:
  1168 		case TRawEvent::EButton2Down:
  1363 		case TRawEvent::EButton2Down:
  1189 		case TRawEvent::EKeyRepeat:
  1384 		case TRawEvent::EKeyRepeat:
  1190  			{
  1385  			{
  1191  			_LIT(KWSERVDebugLogRepeatingKeyArrival,"Repeating key arrives %d");
  1386  			_LIT(KWSERVDebugLogRepeatingKeyArrival,"Repeating key arrives %d");
  1192  			if (wsDebugLog)
  1387  			if (wsDebugLog)
  1193  				wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogRepeatingKeyArrival,aRawEvent.ScanCode());
  1388  				wsDebugLog->MiscMessage(CDebugLogBase::ELogEverything,KWSERVDebugLogRepeatingKeyArrival,aRawEvent.ScanCode());
  1194  			TKeyData keyData;
  1389 			TKeyEvent keyEvent;
  1195  			keyData.iModifiers=iKeyTranslator->GetModifierState();
  1390 			keyEvent.iScanCode = aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE;
  1196 			keyData.iApp=0;
  1391 			keyEvent.iCode = aRawEvent.ScanCode();
  1197 			keyData.iHandle=0;
  1392  			keyEvent.iModifiers = iKeyTranslator->GetModifierState();
  1198 			keyData.iIsCaptureKey=EFalse;
  1393 			ProcessKeyPress(keyEvent, EFalse, aRawEvent.Repeats());
  1199 			keyData.iKeyCode=aRawEvent.ScanCode(); 
       
  1200 			iCaptureKeys->ProcessCaptureKeys(keyData);
       
  1201 			QueueKeyPress(keyData, aRawEvent.ScanCode() __REMOVE_WINS_CHARCODE,NULL,EFalse,aRawEvent.Repeats());
       
  1202  			}
  1394  			}
  1203  			break;
  1395  			break;
  1204 		default:
  1396 		default:
  1205 			break;
  1397 			break;
  1206 		}
  1398 		}
  1207 #ifdef LOG_WSERV_EVENTS
  1399 #ifdef LOG_WSERV_EVENTS
  1208     RDebug::Printf("{EVNT}TWindowServerEvent::ProcessRawEvent Pointer Number= %d  State = %x XY(%d,%d)",TWsPointer::iPointers[0].iNumber,TWsPointer::iPointers[0].iState,TWsPointer::iPointers[0].iPos.iX,TWsPointer::iPointers[0].iPos.iY);
  1400     RDebug::Printf("_WSEVENT_POINTER: TWindowServerEvent::ProcessRawEvent Number= %d  State = %x XY(%d,%d)",TWsPointer::iPointers[0].iNumber,TWsPointer::iPointers[0].iState,TWsPointer::iPointers[0].iPos.iX,TWsPointer::iPointers[0].iPos.iY);
  1209     RDebug::Printf("{EVNT}TWindowServerEvent::ProcessRawEvent Pointer Number= %d  State = %x XY(%d,%d)",TWsPointer::iPointers[1].iNumber,TWsPointer::iPointers[1].iState,TWsPointer::iPointers[1].iPos.iX,TWsPointer::iPointers[1].iPos.iY);
  1401     RDebug::Printf("_WSEVENT_POINTER: TWindowServerEvent::ProcessRawEvent Number= %d  State = %x XY(%d,%d)",TWsPointer::iPointers[1].iNumber,TWsPointer::iPointers[1].iState,TWsPointer::iPointers[1].iPos.iX,TWsPointer::iPointers[1].iPos.iY);
  1210 #endif
  1402 #endif
  1211 	}
  1403 	}
  1212 
  1404 
  1213 void TWindowServerEvent::ProcessKeyEvent(const TKeyEvent &aKeyEvent,TInt aRepeats)
  1405 void TWindowServerEvent::ProcessKeyEvent(const TKeyEvent &aKeyEvent,TInt aRepeats)
  1214 	{
  1406 	{
       
  1407 #ifdef LOG_WSERV_EVENTS
       
  1408     RDebug::Printf("_WSEVENT_KEY: TWindowServerEvent::ProcessKeyEvent, key code: %d, repeat: %d", aKeyEvent.iCode, aRepeats);
       
  1409 #endif
  1215 	TKeyData keyData;
  1410 	TKeyData keyData;
  1216 	keyData.iModifiers=aKeyEvent.iModifiers;
  1411 	keyData.iModifiers=aKeyEvent.iModifiers;
  1217 	keyData.iApp=0;
  1412 	keyData.iApp=0;
  1218 	keyData.iHandle=0;
  1413 	keyData.iHandle=0;
  1219 	keyData.iIsCaptureKey=EFalse;
  1414 	keyData.iIsCaptureKey=EFalse;
  1220 	keyData.iKeyCode=aKeyEvent.iCode;
  1415 	keyData.iKeyCode=aKeyEvent.iCode;
  1221 	if (CKeyboardRepeat::IsAreadyActive())
  1416 	if (CKeyboardRepeat::IsAreadyActive())
  1222 		{
  1417 		{
  1223 		CKeyboardRepeat::CancelRepeat(NULL);
  1418 		CKeyboardRepeat::CancelRepeat(NULL);
  1224 		}
  1419 		}
  1225 	iCaptureKeys->ProcessCaptureKeys(keyData);
  1420 	ProcessKeyPress(aKeyEvent, aRepeats == 0, aRepeats);
  1226 	QueueKeyPress(keyData,aKeyEvent.iScanCode,NULL,aRepeats==0,aRepeats);
  1421 	}
  1227 	}
  1422 
  1228 
  1423 void TWindowServerEvent::AddCaptureKeyL(const TKeyCaptureRequest& aRequest)
  1229 void TWindowServerEvent::AddCaptureKeyL(const TCaptureKey &aCaptureKey)
  1424 	{
  1230 	{
  1425 	iKeyEventRouter->AddCaptureKeyL(aRequest);
  1231 	iCaptureKeys->AddCaptureKeyL(aCaptureKey,aCaptureKey.iKeyCodePattern.iFiller);
  1426 	}
  1232 	}
  1427 
  1233 
  1428 void TWindowServerEvent::UpdateCaptureKeyL(const TKeyCaptureRequest& aRequest)
  1234 void TWindowServerEvent::SetCaptureKey(TUint32 aHandle, const TCaptureKey &aCaptureKey)
  1429 	{
  1235 	{
  1430 	iKeyEventRouter->UpdateCaptureKeyL(aRequest);
  1236 	iCaptureKeys->SetCaptureKey(aHandle, aCaptureKey,aCaptureKey.iKeyCodePattern.iFiller);
  1431 	}
  1237 	}
  1432 
  1238 
  1433 void TWindowServerEvent::CancelCaptureKey(TKeyCaptureType aType, TAny* aHandle)
  1239 void TWindowServerEvent::CancelCaptureKey(TUint32 aHandle)
  1434 	{
  1240 	{
  1435 	iKeyEventRouter->CancelCaptureKey(aType, aHandle);
  1241 	iCaptureKeys->CancelCaptureKey(aHandle);
       
  1242 	}
  1436 	}
  1243 
  1437 
  1244 TInt TWindowServerEvent::GetModifierState()
  1438 TInt TWindowServerEvent::GetModifierState()
  1245 	{
  1439 	{
  1246 	return(iKeyTranslator->GetModifierState());
  1440 	return(iKeyTranslator->GetModifierState());
  1479 	UserSvr::RequestEventCancel();
  1673 	UserSvr::RequestEventCancel();
  1480 	}
  1674 	}
  1481 
  1675 
  1482 void CRawEventReceiver::RunL()
  1676 void CRawEventReceiver::RunL()
  1483 	{
  1677 	{
       
  1678 #ifdef LOG_WSERV_EVENTS
       
  1679     RDebug::Printf("_WSEVENT_KEY: CRawEventReceiver::RunL Entry point for event receiver");
       
  1680 #endif
  1484 //__PROFILE_START(11);
  1681 //__PROFILE_START(11);
  1485 	if (TWsPointer::PreProcessDriverEvent(iEventBuf.Event()
  1682 	if (TWsPointer::PreProcessDriverEvent(iEventBuf.Event()
  1486 #if defined(__WINS__)
  1683 #if defined(__WINS__)
  1487 													,ETrue
  1684 													,ETrue
  1488 #endif
  1685 #endif
  1577 	{
  1774 	{
  1578 	iInitialTime=aInitialTime;
  1775 	iInitialTime=aInitialTime;
  1579 	iTime=aTime;
  1776 	iTime=aTime;
  1580 	}
  1777 	}
  1581 
  1778 
       
  1779 /**
       
  1780 Process timer events.
       
  1781 
       
  1782 Called when the key repeat timer expires, this function generates the
       
  1783 appropriate long key or repeated key event. If the timer was started for
       
  1784 normal key repeat or if the long key event was captured with the automatic
       
  1785 repeat option specified then the timer is restarted.
       
  1786 */
  1582 void CKeyboardRepeat::RunL()
  1787 void CKeyboardRepeat::RunL()
  1583 	{
  1788 	{
  1584 	User::ResetInactivityTime();
  1789 	User::ResetInactivityTime();
  1585 	//WS_ASSERT_DEBUG(iRepeating!=ERepeatNone, EWsPanicTemp);
  1790 	WS_ASSERT_DEBUG(iRepeating != ERepeatNone, EWsPanicKeyRepeat);
  1586 	TBool timer=ETrue;
  1791 	TBool timer=ETrue;
  1587 	if (iRepeating>=ERepeatLong)
  1792 	if (iRepeating>=ERepeatLong)
  1588 		{
  1793 		{
  1589 		// Defensive programming - iLongCapture should never be NULL if iRepeating >= ERepeatLong
  1794 		// Defensive programming - iLongCapture should never be NULL if iRepeating >= ERepeatLong
       
  1795 		WS_ASSERT_DEBUG(iLongCapture != NULL, EWsPanicKeyRepeat);
  1590 		if (iLongCapture)
  1796 		if (iLongCapture)
  1591 			{
  1797 			{
  1592 			iCurrentRepeat.iKey.iApp=REINTERPRET_CAST(TUint32,iLongCapture->iWindowGroup);
  1798 			iCurrentRepeat = iLongRepeat;
  1593 			iCurrentRepeat.iKey.iHandle=0;
  1799 			timer = iLongCapture->iFlags & ELongCaptureRepeatEvents;
  1594 			iCurrentRepeat.iKey.iIsCaptureKey=ETrue;
       
  1595 			iCurrentRepeat.iKey.iKeyCode=iLongCapture->iData.outputKey;
       
  1596 			timer=iLongCapture->iData.flags&ELongCaptureRepeatEvents;
       
  1597 			iRepeating=ERepeatLongRepeated;
  1800 			iRepeating=ERepeatLongRepeated;
  1598 			}
  1801 			}
  1599 		else
  1802 		else
  1600 			{
  1803 			{
  1601 			// Defensive programming - iLongCapture should never be NULL if iRepeating >= ERepeatLong
  1804 			// Defensive programming - iLongCapture should never be NULL if iRepeating >= ERepeatLong
  1605 		}
  1808 		}
  1606 	if (timer)
  1809 	if (timer)
  1607 		After(iTime);
  1810 		After(iTime);
  1608 	else
  1811 	else
  1609 		iRepeating=ERepeatNone;
  1812 		iRepeating=ERepeatNone;
  1610 	TWindowServerEvent::QueueKeyPress(iCurrentRepeat.iKey,iCurrentRepeat.iScanCode,iFocus,EFalse,1);
  1813 
  1611 	}
  1814 	TWindowServerEvent::QueueKeyPress(iCurrentRepeat.iOutput, ETrue, 1);
  1612 
  1815 	}
  1613 TBool CKeyboardRepeat::StartRepeat(const TKeyData &aKey, TInt aScanCode, CWsWindowGroup *aRepeatFocus, CWsCaptureLongKey* aLongCapture)
  1816 
       
  1817 /**
       
  1818 Start key repeat and long key press timer
       
  1819 
       
  1820 @param	aInputScanCode	Original scan code (before routing)
       
  1821 @param	aShortEvent		Short key event (routing plug-in output)
       
  1822 @param	aLongEvent		Pointer to long key event (routing plug-in output)
       
  1823 						or NULL if none.
       
  1824 
       
  1825 Note: When aLongEvent != NULL, iCurrentRepeat reflects the short key event
       
  1826 until the timer has expired. This is necessary to allow a delayed short key
       
  1827 event to be delivered by KeyUp(). CancelRepeat() must therefore examine
       
  1828 iCurrentRepeat or iLongRepeat according to the repeat type in iRepeat.
       
  1829 */
       
  1830 void CKeyboardRepeat::StartRepeat(TInt aInputScanCode, const TKeyEventRouterOutput& aShortEvent, const TKeyEventRouterOutput* aLongEvent)
  1614 	{
  1831 	{
  1615 	TTimeIntervalMicroSeconds32 time;
  1832 	TTimeIntervalMicroSeconds32 time;
  1616 	TBool ret=EFalse;
  1833 	iCurrentRepeat.iInputScanCode = aInputScanCode;
  1617 	iCurrentRepeat.iScanCode=aScanCode;
  1834 	iCurrentRepeat.iOutput = aShortEvent;
  1618 	iCurrentRepeat.iKey=aKey;
  1835 
  1619 
  1836 	if (aLongEvent)
  1620 	if (aLongCapture)
  1837 		{
  1621 		{
  1838 		iRepeating = ERepeatLong;
  1622 		iLongCapture=aLongCapture;
  1839 		iLongRepeat.iInputScanCode = aInputScanCode;
  1623 		iRepeating=ERepeatLong;
  1840 		iLongRepeat.iOutput = *aLongEvent;
  1624 		time=aLongCapture->iData.delay;
  1841 		iLongCapture = static_cast<CWsCaptureLongKey*>(aLongEvent->iCaptureHandle);
  1625 		ret=!(aLongCapture->iData.flags&ELongCaptureShortEventImmediately);
  1842 		time = iLongCapture->iDelay;
  1626 		//need window group from long capture key or even better delete it altogether.
       
  1627 		iFocus=aLongCapture->WindowGroup();
       
  1628 		}
  1843 		}
  1629 	else
  1844 	else
  1630 		{
  1845 		{
  1631 		iFocus=aRepeatFocus;
  1846 		iLongCapture = NULL;
  1632 		iRepeating=ERepeatNormal;
  1847 		iRepeating=ERepeatNormal;
  1633 		time=iInitialTime;
  1848 		time=iInitialTime;
  1634 		}
  1849 		}
  1635 	iThis->After(time);
  1850 	iThis->After(time);
  1636 	return ret;
  1851 	}
  1637 	}
  1852 
  1638 
  1853 /**
       
  1854 Cancel key repeat processing
       
  1855 */
  1639 void CKeyboardRepeat::doCancelRepeat()
  1856 void CKeyboardRepeat::doCancelRepeat()
  1640 	{
  1857 	{
  1641 	iRepeating=ERepeatNone;
  1858 	iRepeating=ERepeatNone;
  1642 	iThis->Cancel();
  1859 	iThis->Cancel();
  1643 	}
  1860 	}
  1644 
  1861 
       
  1862 /**
       
  1863 Cancel any key repeat associated with the specified window group
       
  1864 
       
  1865 @param	aRepeatFocus	Destination window group or NULL for all
       
  1866 */
  1645 void CKeyboardRepeat::CancelRepeat(CWsWindowGroup *aRepeatFocus)
  1867 void CKeyboardRepeat::CancelRepeat(CWsWindowGroup *aRepeatFocus)
  1646 	{
  1868 	{
  1647 	if (aRepeatFocus==NULL || aRepeatFocus==iFocus)
  1869 	if (iRepeating != ERepeatNone)
  1648 		{
  1870 		{
  1649 		if (iRepeating)
  1871 		if (aRepeatFocus == NULL ||
  1650 			doCancelRepeat();
  1872 			(iRepeating == ERepeatNormal) && (aRepeatFocus == iCurrentRepeat.iOutput.iWindowGroup) ||
  1651 		iAlternateRepeatExists=EFalse;
  1873 			(iRepeating >= ERepeatLong) && (aRepeatFocus == iLongRepeat.iOutput.iWindowGroup))
  1652 		}
       
  1653 	else if (iRepeating >= ERepeatLong)
       
  1654 		{
       
  1655 		// Defensive programming - iLongCapture should never be NULL if iRepeating >= ERepeatLong
       
  1656 		if (iLongCapture && iLongCapture->iWindowGroup == aRepeatFocus)
       
  1657 			{
  1874 			{
  1658 			doCancelRepeat();
  1875 			doCancelRepeat();
  1659 			iAlternateRepeatExists=EFalse;
  1876 			iAlternateRepeatExists=EFalse;
  1660 			}
  1877 			}
  1661 		}
  1878 		}
  1662 	}
  1879 	}
  1663 
  1880 
  1664 void CKeyboardRepeat::CancelRepeat(CWsWindowGroup *aRepeatFocus,TUint aScanCode,TBool aLongCaptureFlag,TUint aModifiers)
  1881 /**
       
  1882 Cancel any key repeat associated with the specified capture handle
       
  1883 
       
  1884 @param	aCaptureHandle		Handle to capture request
       
  1885 @param	aLongCaptureFlag	ETrue for long key capture, EFalse for normal key
       
  1886 */
       
  1887 void CKeyboardRepeat::CancelRepeat(const TAny* aCaptureHandle, TBool aLongCaptureFlag)
  1665 	{
  1888 	{
  1666 	if (aLongCaptureFlag)
  1889 	if (aLongCaptureFlag)
  1667 		{
  1890 		{
  1668 		// long capture key is cancelled
  1891 		// Cancel repeat for long capture key
  1669 		if (iRepeating >= ERepeatLong && iCurrentRepeat.iScanCode==aScanCode)			
  1892 		if (iRepeating >= ERepeatLong && aCaptureHandle == iLongRepeat.iOutput.iCaptureHandle)
  1670 				{
  1893 			{
  1671 				// Defensive programming - iLongCapture should never be NULL if iRepeating >= ERepeatLong
  1894 			doCancelRepeat();
  1672 				if (iLongCapture && aRepeatFocus == iLongCapture->iWindowGroup &&
  1895 			iAlternateRepeatExists=EFalse;
  1673 					(aModifiers & iLongCapture->iData.modifierMask) == iLongCapture->iData.modifiers)
  1896 			}
  1674 					{
       
  1675 					doCancelRepeat();
       
  1676 					iAlternateRepeatExists=EFalse;
       
  1677 					}
       
  1678 				}
       
  1679 		}
  1897 		}
  1680 	else
  1898 	else
  1681 		{
  1899 		{
  1682 		// normal capture key is cancelled
  1900 		// Cancel repeat for normal capture key
  1683 		if (aRepeatFocus==iFocus)
  1901 		if (iRepeating == ERepeatNormal && aCaptureHandle == iCurrentRepeat.iOutput.iCaptureHandle)
  1684 			{
  1902 			{
  1685 			if (iRepeating>=ERepeatNormal && iCurrentRepeat.iScanCode==aScanCode)
  1903 			doCancelRepeat();
  1686 				{
       
  1687 				doCancelRepeat();
       
  1688 				}
       
  1689 			iAlternateRepeatExists=EFalse;
  1904 			iAlternateRepeatExists=EFalse;
  1690 			}
  1905 			}
  1691 		}
  1906 		}
  1692 	}
  1907 	}
  1693 	
  1908 	
       
  1909 /**
       
  1910 Process a key down event during key repeat.
       
  1911 The current repeat data is saved for possible restoration after rollover.
       
  1912 */
  1694 void CKeyboardRepeat::KeyDown()
  1913 void CKeyboardRepeat::KeyDown()
  1695 	{
  1914 	{
  1696 	if (iRepeating!=ERepeatNone)
  1915 	if (iRepeating!=ERepeatNone)
  1697 		{
  1916 		{
  1698 		if (iRepeating==ERepeatNormal && iRepeatRollover>0) // 1 Allow key repeat rollover
  1917 		if (iRepeating==ERepeatNormal && iRepeatRollover>0) // 1 Allow key repeat rollover
  1702 			}
  1921 			}
  1703 		doCancelRepeat();
  1922 		doCancelRepeat();
  1704 		}
  1923 		}
  1705 	}
  1924 	}
  1706 
  1925 
       
  1926 /**
       
  1927 Process a key up event during key repeat.
       
  1928 Send delayed short key event if necessary for long key event processing.
       
  1929 Switch to alternate repeat if rollover key was released.
       
  1930 
       
  1931 @param	aScanCode	Scan code
       
  1932 */
  1707 void CKeyboardRepeat::KeyUp(TInt aScanCode)
  1933 void CKeyboardRepeat::KeyUp(TInt aScanCode)
  1708 	{
  1934 	{
  1709 	if (iAlternateRepeatExists && iAlternateRepeat.iScanCode==aScanCode)
  1935 	if (iAlternateRepeatExists && iAlternateRepeat.iInputScanCode == aScanCode)
  1710 		iAlternateRepeatExists=EFalse;
  1936 		iAlternateRepeatExists=EFalse;
  1711 	if (iRepeating!=ERepeatNone && iCurrentRepeat.iScanCode==aScanCode)
  1937 	if (iRepeating != ERepeatNone && iCurrentRepeat.iInputScanCode == aScanCode)
  1712 		{
  1938 		{
  1713 		if (iRepeating==ERepeatLong)
  1939 		if (iRepeating==ERepeatLong)
  1714 			{
  1940 			{
  1715 			// Defensive programming - iLongCapture should never be NULL if iRepeating >= ERepeatLong			
  1941 			// Defensive programming - iLongCapture should never be NULL if iRepeating >= ERepeatLong			
  1716 			if (iLongCapture && !(iLongCapture->iData.flags&ELongCaptureShortEventImmediately))
  1942 			WS_ASSERT_DEBUG(iLongCapture != NULL, EWsPanicKeyRepeat);
       
  1943 			if (iLongCapture && !(iLongCapture->iFlags & ELongCaptureShortEventImmediately))
  1717 				{
  1944 				{
  1718 				TWindowServerEvent::QueueKeyPress(iCurrentRepeat.iKey,iCurrentRepeat.iScanCode,NULL,EFalse,0);	
  1945 				TWindowServerEvent::QueueKeyPress(iCurrentRepeat.iOutput, EFalse, 0);
  1719 				}
  1946 				}
  1720 			}			
  1947 			}			
  1721 		if (iAlternateRepeatExists)
  1948 		if (iAlternateRepeatExists)
  1722 			{
  1949 			{
  1723 			iAlternateRepeatExists=EFalse;
  1950 			iAlternateRepeatExists=EFalse;