bluetoothengine/bthid/keyboard/src/keyboard.cpp
branchRCL_3
changeset 39 5a89845f78e2
parent 16 b23265fb36da
child 53 eede1356aa52
equal deleted inserted replaced
35:95674584745d 39:5a89845f78e2
    21 #include <w32std.h>
    21 #include <w32std.h>
    22 #include <coedef.h>
    22 #include <coedef.h>
    23 #include <eiksvdef.h>
    23 #include <eiksvdef.h>
    24 #include <apgcli.h>
    24 #include <apgcli.h>
    25 #include <apgtask.h>
    25 #include <apgtask.h>
    26 #include <apacmdln.h>
    26 #include <e32keys.h>
    27 #include <e32property.h>
    27 #include <avkondomainpskeys.h>
    28 
    28 
    29 #include "hidtranslate.h"
    29 #include "hidtranslate.h"
    30 #include "finder.h"
    30 #include "finder.h"
    31 #include "keyboard.h"
    31 #include "keyboard.h"
    32 #include "layoutmgr.h"
    32 #include "layoutmgr.h"
    50 // Key repeat parameters to be configured
    50 // Key repeat parameters to be configured
    51 const TInt KRepeatEndTimeout = 5000000; // 5 seconds
    51 const TInt KRepeatEndTimeout = 5000000; // 5 seconds
    52 
    52 
    53 const TInt KKeyRepeatDelay = 500000;
    53 const TInt KKeyRepeatDelay = 500000;
    54 const TInt KKeyRepeatInterval = 75000;
    54 const TInt KKeyRepeatInterval = 75000;
    55 _LIT(KAppName, "PaintCursor.exe");
    55 
       
    56 // The bitmap of modifier byte is defined in the HID spec.
       
    57 // 8.3 Report Format for Array Items (HID1_11.pdf p56)
       
    58 // 
       
    59 // bit  description     mask
       
    60 // -------------------------
       
    61 // 0    LEFT CTRL     = 0x01
       
    62 // 1    LEFT SHIFT    = 0x02
       
    63 // 2    LEFT ALT      = 0x04
       
    64 // 3    LEFT GUI      = 0x08
       
    65 // 4    RIGHT CTRL    = 0x10
       
    66 // 5    RIGHT SHIFT   = 0x20
       
    67 // 6    RIGHT ALT     = 0x40
       
    68 // 7    RIGHT GUI     = 0x80
       
    69 
       
    70 const TUint KHidModifierCtrl = 0x01;
       
    71 const TUint KHidModifierCtrlRight = 0x10;
       
    72 const TUint KHidModifierAlt = 0x04;
       
    73 const TUint KHidModifierAltRight = 0x40;
       
    74 const TUint KHidModifierShift = 0x02;
       
    75 const TUint KHidModifierShiftRight = 0x20;
       
    76 
    56 //----------------------------------------------------------------------------
    77 //----------------------------------------------------------------------------
    57 // CHidKeyboardDriver::CHidKeyboardDriver
    78 // CHidKeyboardDriver::CHidKeyboardDriver
    58 //----------------------------------------------------------------------------
    79 //----------------------------------------------------------------------------
    59 //
    80 //
    60 CHidKeyboardDriver::CHidKeyboardDriver(MDriverAccess* aGenericHid) :
    81 CHidKeyboardDriver::CHidKeyboardDriver(MDriverAccess* aGenericHid) :
   110     iRepeatEndTimer = CTimeOutTimer::NewL(EPriorityNormal, *this);
   131     iRepeatEndTimer = CTimeOutTimer::NewL(EPriorityNormal, *this);
   111     iAppMenuId = AppMenuId();
   132     iAppMenuId = AppMenuId();
   112     iPhoneAppId = PhoneAppId();
   133     iPhoneAppId = PhoneAppId();
   113     iIdleAppId = IdleAppId();
   134     iIdleAppId = IdleAppId();
   114 
   135 
   115     iComboDevice = EFalse;
       
   116 
       
   117     iSettings = CBtHidSettings::NewL();
   136     iSettings = CBtHidSettings::NewL();
       
   137     
       
   138     // create a keylock session
       
   139 /*    TInt err = iKeyLock.Connect();
       
   140     TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::ConstructL: key lock err = %d"), err));
       
   141     User::LeaveIfError(err);    */
   118     }
   142     }
   119 
   143 
   120 //----------------------------------------------------------------------------
   144 //----------------------------------------------------------------------------
   121 // CHidKeyboardDriver::~CHidKeyboardDriver
   145 // CHidKeyboardDriver::~CHidKeyboardDriver
   122 //----------------------------------------------------------------------------
   146 //----------------------------------------------------------------------------
   134     for (TInt i = 0; i < KNumInputFieldTypes; ++i)
   158     for (TInt i = 0; i < KNumInputFieldTypes; ++i)
   135         {
   159         {
   136         iKeys[i].Reset();
   160         iKeys[i].Reset();
   137         }
   161         }
   138 
   162 
   139     iPointBufQueue.Close();
       
   140 
       
   141     if (iComboDevice)
       
   142         {
       
   143         RProperty::Set( KPSUidBthidSrv, KBTMouseCursorState, ECursorNotInitialized );
       
   144         }
       
   145 
       
   146     if (iSettings)
   163     if (iSettings)
   147         delete iSettings;
   164         delete iSettings;
   148     }
   165 
   149 
   166 //    iKeyLock.Close();
   150 void CHidKeyboardDriver::MoveCursor(const TPoint& aPoint)
   167     }
   151     {
   168 
   152     DBG(RDebug::Print(
       
   153                     _L("CHidKeyboard::MoveCursor")));
       
   154 
       
   155     PostPointer(aPoint);
       
   156     }
       
   157 // ---------------------------------------------------------------------------
       
   158 // CHidMouseDriver::PostPointer
       
   159 // Save the event to the buffer
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 TInt CHidKeyboardDriver::PostPointer(const TPoint& aPoint)
       
   163     {
       
   164     DBG(RDebug::Print(_L("CHidKeyboard::PostPointer")));
       
   165     iPointerBuffer.iPoint[iPointerBuffer.iNum] = aPoint;
       
   166     iPointerBuffer.iType[iPointerBuffer.iNum] = KBufferPlainPointer;
       
   167     iPointerBuffer.iNum++;
       
   168     TInt ret = KErrNone;
       
   169 
       
   170     if (iPointerBuffer.iNum > KPMaxEvent)
       
   171         {
       
   172         ret = iPointBufQueue.Send(iPointerBuffer);
       
   173         iPointerBuffer.iNum = 0;
       
   174         }
       
   175     return ret;
       
   176     }
       
   177 
       
   178 TInt CHidKeyboardDriver::SendButtonEvent(TBool aButtonDown)
       
   179     {
       
   180     DBG(RDebug::Print(
       
   181                     _L("CHidKeyboard::SendButtonEvent")));
       
   182     iPointerBuffer.iPoint[iPointerBuffer.iNum] = TPoint(0, 0);
       
   183     iPointerBuffer.iType[iPointerBuffer.iNum] = aButtonDown
       
   184                                                             ? KBufferPenDown
       
   185                                                                : KBufferPenUp;
       
   186     iPointerBuffer.iNum++;
       
   187     TInt ret = iPointBufQueue.Send(iPointerBuffer);
       
   188     iPointerBuffer.iNum = 0;
       
   189     return ret;
       
   190     }
       
   191 //----------------------------------------------------------------------------
   169 //----------------------------------------------------------------------------
   192 // CHidKeyboardDriver:::StartL
   170 // CHidKeyboardDriver:::StartL
   193 //----------------------------------------------------------------------------
   171 //----------------------------------------------------------------------------
   194 //
   172 //
   195 void CHidKeyboardDriver::StartL(TInt aConnectionId)
   173 void CHidKeyboardDriver::StartL(TInt aConnectionId)
   196     {
   174     {
   197         TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::StartL")));
   175         TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::StartL")));
   198     aConnectionId = aConnectionId;
   176     aConnectionId = aConnectionId;
       
   177 
   199     // No keys are pressed:
   178     // No keys are pressed:
   200     iModifiers = 0;
   179     iModifiers = 0;
   201     for (TInt i = 0; i < KNumInputFieldTypes; ++i)
   180     for (TInt i = 0; i < KNumInputFieldTypes; ++i)
   202         {
   181         {
   203         if (iField[i])
   182         if (iField[i])
   231     if (sameCategory)
   210     if (sameCategory)
   232         {
   211         {
   233         //Used the layoutID from CenRep
   212         //Used the layoutID from CenRep
   234         iLayoutMgr.SetLayout(iLastSelectedLayout);
   213         iLayoutMgr.SetLayout(iLastSelectedLayout);
   235         }
   214         }
   236     TInt err = iPointBufQueue.OpenGlobal(KMsgBTMouseBufferQueue);   
       
   237     if (err == KErrNotFound)
       
   238         {
       
   239         User::LeaveIfError(iPointBufQueue.CreateGlobal(KMsgBTMouseBufferQueue, KPointQueueLen));    
       
   240         }
       
   241     else
       
   242         {
       
   243         User::LeaveIfError( err );
       
   244         }    
       
   245 
   215 
   246     // Ready to process keyboard events:
   216     // Ready to process keyboard events:
   247     iDriverState = EInitialised;
   217     iDriverState = EInitialised;
   248 
       
   249     if (iComboDevice)
       
   250         {
       
   251         LaunchApplicationL(KAppName);
       
   252         RProperty::Set( KPSUidBthidSrv, KBTMouseCursorState, ECursorShow );
       
   253         }
       
   254 
   218 
   255     }
   219     }
   256 
   220 
   257 //----------------------------------------------------------------------------
   221 //----------------------------------------------------------------------------
   258 // CHidKeyboardDriver::InitialiseL
   222 // CHidKeyboardDriver::InitialiseL
   284 //
   248 //
   285 void CHidKeyboardDriver::Stop()
   249 void CHidKeyboardDriver::Stop()
   286     {
   250     {
   287     iDriverState = EDisabled;
   251     iDriverState = EDisabled;
   288     CancelAllKeys();
   252     CancelAllKeys();
   289     if (iComboDevice)
       
   290         {
       
   291         RProperty::Set( KPSUidBthidSrv, KBTMouseCursorState, ECursorNotInitialized );
       
   292         }
       
   293     }
       
   294 
       
   295 //----------------------------------------------------------------------------
       
   296 // CHidMouseDriver::LaunchApplicationL
       
   297 //----------------------------------------------------------------------------
       
   298 //
       
   299 void CHidKeyboardDriver::LaunchApplicationL(const TDesC& aName)
       
   300     {
       
   301     //Check if application is already running in the background
       
   302     TApaTaskList tasks(iWsSession);
       
   303     TApaTask task = tasks.FindApp(aName);
       
   304     if (task.Exists())
       
   305         {
       
   306         // Application is active, so just bring to foreground
       
   307         }
       
   308     else
       
   309         {
       
   310         // If application is not running, then create a new one
       
   311         CApaCommandLine* cmd = CApaCommandLine::NewLC();
       
   312         cmd->SetExecutableNameL(aName);
       
   313         cmd->SetCommandL(EApaCommandBackground); // EApaCommandRun
       
   314 
       
   315         RApaLsSession arcSession;
       
   316         //connect to AppArc server
       
   317         User::LeaveIfError(arcSession.Connect());
       
   318         CleanupClosePushL(arcSession);
       
   319         User::LeaveIfError(arcSession.StartApp(*cmd));
       
   320         arcSession.Close();
       
   321         CleanupStack::PopAndDestroy(2);
       
   322         }
       
   323 
       
   324     }
   253     }
   325 
   254 
   326 // ----------------------------------------------------------------------
   255 // ----------------------------------------------------------------------
   327 // CHidDriver mandatory functions:
   256 // CHidDriver mandatory functions:
   328 
   257 
   337     switch (aChannel)
   266     switch (aChannel)
   338         {
   267         {
   339         case CHidTransport::EHidChannelInt:
   268         case CHidTransport::EHidChannelInt:
   340             if (EInitialised == iDriverState)
   269             if (EInitialised == iDriverState)
   341                 {
   270                 {
   342                 if (iComboDevice)
       
   343                     {
       
   344                     TInt mouseStatus;
       
   345                     TInt err = RProperty::Get( KPSUidBthidSrv, KBTMouseCursorState, mouseStatus );
       
   346                     if ( !err &&
       
   347                         ((static_cast<THidMouseCursorState>(mouseStatus) == ECursorRedraw)|| 
       
   348                          (static_cast<THidMouseCursorState>(mouseStatus) == ECursorReset)) )
       
   349                         {
       
   350                         err = RProperty::Set( KPSUidBthidSrv, KBTMouseCursorState, ECursorShow );
       
   351                         DBG(RDebug::Print(
       
   352                                  _L("[BTHID]\tCHidKeyboardDriver::DataIn() ECursorRedraw ||ECursorReset ")) );
       
   353                         }
       
   354 
       
   355                     CursorRedraw();
       
   356                     }
       
   357                 InterruptData(aPayload);
   271                 InterruptData(aPayload);
   358                 }
   272                 }
   359             break;
   273             break;
   360 
   274 
   361         case CHidTransport::EHidChannelCtrl:
   275         case CHidTransport::EHidChannelCtrl:
   384     {
   298     {
   385     RDebug::Print(_L("CHidKeyboardDriver::Disconnected(%d)"), aReason);
   299     RDebug::Print(_L("CHidKeyboardDriver::Disconnected(%d)"), aReason);
   386     Stop();
   300     Stop();
   387     }
   301     }
   388 
   302 
   389 void CHidKeyboardDriver::UpdateXY(TInt aFieldIndex, const TDesC8& aReport)
       
   390     {
       
   391     //    DBG(RDebug::Print(_L("[HID]\tCHidMouseDriver::UpdateModifiers()")));
       
   392 
       
   393     // Translate the HID usage values into a boot protocol style
       
   394     // modifier bitmask:
       
   395     //
       
   396     TReportTranslator report(aReport, iMouseField[aFieldIndex]);
       
   397 
       
   398     TInt Xvalue = 0;
       
   399     TInt Yvalue = 0;
       
   400 
       
   401     TInt errX = report.GetValue(Xvalue, EGenericDesktopUsageX);
       
   402     TInt errY = report.GetValue(Yvalue, EGenericDesktopUsageY);
       
   403 
       
   404     DBG(RDebug::Print(_L("[HID]\tCHidMouseDriver::UpdateXY (%d,%d)"), Xvalue, Yvalue));
       
   405     if ((Xvalue != 0) || (Yvalue != 0))
       
   406         {
       
   407         MoveCursor(TPoint(Xvalue, Yvalue));
       
   408         }
       
   409     }
       
   410 
       
   411 void CHidKeyboardDriver::UpdateWheel(TInt aFieldIndex, const TDesC8& aReport)
       
   412     {
       
   413     TReportTranslator report(aReport, iMouseField[aFieldIndex]);
       
   414 
       
   415     TInt Yvalue = 0;
       
   416 
       
   417     TInt errY = report.GetValue(Yvalue, EGenericDesktopUsageWheel);
       
   418     DBG(RDebug::Print(_L("[HID]\tCHidMouseDriver::UpdateWheel (%d)"), Yvalue));
       
   419     TInt absValue(Abs(Yvalue));
       
   420     if ((errY == KErrNone) && (absValue >= 1))
       
   421         {
       
   422         TRawEvent rawEvent;
       
   423         for (TInt ii = 0; ii < absValue; ii++)
       
   424             {
       
   425             rawEvent.Set(TRawEvent::EKeyDown,
       
   426                     (Yvalue > 0) ? EStdKeyUpArrow : EStdKeyDownArrow);
       
   427             UserSvr::AddEvent(rawEvent);
       
   428             rawEvent.Set(TRawEvent::EKeyUp,
       
   429                     (Yvalue > 0) ? EStdKeyUpArrow : EStdKeyDownArrow);
       
   430             UserSvr::AddEvent(rawEvent);
       
   431             }
       
   432         }
       
   433     DBG(RDebug::Print(_L("[HID]\t  new iModifiers = %02x"), iModifiers));
       
   434     }
       
   435 
       
   436 void CHidKeyboardDriver::UpdateButtons(TInt aFieldIndex,
       
   437         const TDesC8& aReport)
       
   438     {
       
   439     DBG(RDebug::Print(_L("[HID]\tCHidMouseDriver::UpdateButtons()")));
       
   440     // Translate the HID usage values into a boot protocol style
       
   441     // modifier bitmask:
       
   442     //
       
   443     const TInt KButton1 = 1;
       
   444     const TInt KButton2 = 2;
       
   445     const TInt KButton3 = 3;
       
   446 
       
   447     TBool buttonPressed(EFalse);
       
   448 
       
   449     DBG(RDebug::Print(_L("[HID]\tCHidMouseDriver::UpdateButtons() %d, %d, %d"),
       
   450                     iMouseField[aFieldIndex]->UsagePage(),
       
   451                     iMouseField[aFieldIndex]->UsageMin(),
       
   452                     iMouseField[aFieldIndex]->UsageMax()));
       
   453     (void) aFieldIndex;
       
   454     // Hack but works
       
   455     // We dont come here if the report is wrong?
       
   456     TInt buttonByte = aReport[1];
       
   457     if (KButton1 == buttonByte)
       
   458         {
       
   459         DBG(RDebug::Print(_L("[HID]\tCHidMouseDriver::UpdateButtons() Button1")));
       
   460         buttonPressed = ETrue;
       
   461         }
       
   462 
       
   463     if (KButton2 == buttonByte)
       
   464         {
       
   465         DBG(RDebug::Print(_L("[HID]\tCHidMouseDriver::UpdateButtons() Button2")));
       
   466         if (!iButton2Down)
       
   467             {
       
   468             iButton2Down = ETrue;
       
   469             TRawEvent rawEvent;
       
   470             rawEvent.Set(TRawEvent::EKeyDown, EStdKeyApplication0);
       
   471             CursorRedraw();
       
   472             UserSvr::AddEvent(rawEvent);
       
   473             }
       
   474         }
       
   475     else
       
   476         {
       
   477         if (iButton2Down)
       
   478             {
       
   479             iButton2Down = EFalse;
       
   480             TRawEvent rawEvent;
       
   481             rawEvent.Set(TRawEvent::EKeyUp, EStdKeyApplication0);
       
   482             CursorRedraw();
       
   483             UserSvr::AddEvent(rawEvent);
       
   484             }
       
   485         }
       
   486 
       
   487     if (KButton3 == buttonByte)
       
   488         {
       
   489         DBG(RDebug::Print(_L("[HID]\tCHidMouseDriver::UpdateButtons() Button3")));
       
   490         buttonPressed = ETrue;
       
   491         }
       
   492 
       
   493     if (buttonPressed)
       
   494         {
       
   495         if (!iButtonDown)
       
   496             {
       
   497             iButtonDown = ETrue;
       
   498             SendButtonEvent(ETrue);//Send Mouse Button Down
       
   499             }
       
   500         }
       
   501     else
       
   502         {
       
   503         if (iButtonDown)
       
   504             {
       
   505             iButtonDown = EFalse;
       
   506             SendButtonEvent(EFalse); //Send Mouse Button Up
       
   507             }
       
   508         }
       
   509     }
       
   510 //----------------------------------------------------------------------------
   303 //----------------------------------------------------------------------------
   511 // CHidKeyboardDriver::InterruptData
   304 // CHidKeyboardDriver::InterruptData
   512 //----------------------------------------------------------------------------
   305 //----------------------------------------------------------------------------
   513 //
   306 //
   514 void CHidKeyboardDriver::InterruptData(const TDesC8& aPayload)
   307 void CHidKeyboardDriver::InterruptData(const TDesC8& aPayload)
   529         DBG(RDebug::Print(
   322         DBG(RDebug::Print(
   530                         _L("[HID]\tCHidKeyboardDriver::InterruptData()  report[%d] =  %d"),
   323                         _L("[HID]\tCHidKeyboardDriver::InterruptData()  report[%d] =  %d"),
   531                         ii, nextByte));
   324                         ii, nextByte));
   532         }
   325         }
   533 #endif
   326 #endif
   534     TBool mouseEvent(EFalse);
       
   535     if (iMouseField[EMouseXY] && iMouseField[EMouseXY]->IsInReport(firstByte))
       
   536         {
       
   537         UpdateXY(EMouseXY, aPayload);
       
   538         mouseEvent = ETrue;
       
   539         }
       
   540 
       
   541     if (iMouseField[EMouseButtons] && iMouseField[EMouseButtons]->IsInReport(
       
   542             firstByte))
       
   543         {
       
   544         UpdateButtons(EMouseButtons, aPayload);
       
   545         mouseEvent = ETrue;
       
   546         }
       
   547     if (iMouseField[EMouseXY] && iMouseField[EMouseXY]->IsInReport(firstByte))
       
   548         {
       
   549         UpdateWheel(EMouseWheel, aPayload);
       
   550         mouseEvent = ETrue;
       
   551         }
       
   552     DBG(RDebug::Print(_L("[HID]\tCHidKeyboardDriver::InterruptData()  mouseevent %d"),
       
   553                     mouseEvent));
       
   554     if (mouseEvent)
       
   555         {
       
   556         return;
       
   557         }
       
   558     // First check for any rollover errors:
   327     // First check for any rollover errors:
   559     //
   328     //
   560     TInt i;
   329     TInt i;
   561     for (i = 0; i < KNumInputFieldTypes; ++i)
   330     for (i = 0; i < KNumInputFieldTypes; ++i)
   562         {
   331         {
   756                 TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::KeyEvent:Launch failed")));
   525                 TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::KeyEvent:Launch failed")));
   757             }
   526             }
   758 
   527 
   759         //check if the key is multimedia key that needs to be sent as RawEvent and send it.
   528         //check if the key is multimedia key that needs to be sent as RawEvent and send it.
   760         // if key event is consumed don't send it anymore.
   529         // if key event is consumed don't send it anymore.
   761         if (!HandleMultimediaKeys(decodedKeys.iScanCode, aIsKeyDown,
   530         if (!HandleKeyMapping(decodedKeys, aIsKeyDown, iModifiers))
   762                 iModifiers)) //check if the key is multimedia key that needs to be sent as RawEvent and send it.
       
   763             {
   531             {
   764             if (decodedKeys.iScanCode != EStdKeyNull)
   532             if (decodedKeys.iScanCode != EStdKeyNull)
   765                 {
   533                 {
   766                 TKeyEvent event =
   534                 TKeyEvent event =
   767                         TKeyEventFromScanCode(decodedKeys.iScanCode);
   535                         TKeyEventFromScanCode(decodedKeys.iScanCode);
   776                     TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::KeyEvent: ScanCode: %d %c"), decodedKeys.iScanCode, decodedKeys.iScanCode));
   544                     TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::KeyEvent: ScanCode: %d %c"), decodedKeys.iScanCode, decodedKeys.iScanCode));
   777                 TInt unikey = key.iUnicode;
   545                 TInt unikey = key.iUnicode;
   778                 //Send key codes differently to idle app
   546                 //Send key codes differently to idle app
   779                 if ((IsDigitKey(decodedKeys.iScanCode) || IsSpecialHandleKey(
   547                 if ((IsDigitKey(decodedKeys.iScanCode) || IsSpecialHandleKey(
   780                         unikey) || decodedKeys.iScanCode == EStdKeyYes
   548                         unikey) || decodedKeys.iScanCode == EStdKeyYes
   781                         || decodedKeys.iScanCode == EStdKeyBackspace)
   549                         || decodedKeys.iScanCode == EStdKeyBackspace
       
   550                         || decodedKeys.iScanCode == EStdKeyNo)
   782                         && IsPhoneAppTopMost())
   551                         && IsPhoneAppTopMost())
   783                     {
   552                     {
   784                         TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::KeyEvent: Send event %c to idle editor"), unikey));
   553                         TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::KeyEvent: Send event %c to idle editor"), unikey));
   785                     HandleTelephoneAppKeys(decodedKeys.iScanCode, unikey,
   554                     HandleTelephoneAppKeys(decodedKeys.iScanCode, unikey,
   786                             aIsKeyDown);
   555                             aIsKeyDown);
  1521 
  1290 
  1522     if ((iField[EStandardKeys] != 0) && (iField[EModifierKeys] != 0))
  1291     if ((iField[EStandardKeys] != 0) && (iField[EModifierKeys] != 0))
  1523         {
  1292         {
  1524         valid = KErrNone;
  1293         valid = KErrNone;
  1525         }
  1294         }
  1526 
       
  1527     TMouseFinder mousefinder;
       
  1528     search.SearchL(aReportRoot, &mousefinder);
       
  1529     iMouseField[EMouseButtons] = mousefinder.ButtonsField();
       
  1530     iMouseField[EMouseXY] = mousefinder.XYField();
       
  1531     iMouseField[EMouseWheel] = mousefinder.WheelField();
       
  1532 
       
  1533     if ((iMouseField[EMouseButtons] != 0) && (iMouseField[EMouseXY] != 0))
       
  1534         {
       
  1535         iComboDevice = ETrue;
       
  1536         }
       
  1537 
       
  1538         TRACE_INFO( (
  1295         TRACE_INFO( (
  1539                         _L("CHidKeyboard::CanHandleReport() returning %d"), valid));
  1296                         _L("CHidKeyboard::CanHandleReport() returning %d"), valid));
  1540 
  1297 
  1541     return valid;
  1298     return valid;
  1542     }
  1299     }
  1672 //        EModifierRightFunc  | EModifierFunc    // 0x3000  (report bit 7)
  1429 //        EModifierRightFunc  | EModifierFunc    // 0x3000  (report bit 7)
  1673 //        };
  1430 //        };
  1674 //----------------------------------------------------------------------------
  1431 //----------------------------------------------------------------------------
  1675 //
  1432 //
  1676 
  1433 
  1677 TBool CHidKeyboardDriver::HandleMultimediaKeys(TUint16 aScancodeKey,
  1434 TBool CHidKeyboardDriver::HandleKeyMapping(TDecodedKeyInfo& aKey,
  1678         TBool aIsKeyDown, TUint8 aHIDModifiers)
  1435     TBool aIsKeyDown,
  1679     {
  1436     TUint8 aHIDModifiers)
  1680     TBool ret = HandleMultimediaKeysForNokia(aScancodeKey, aIsKeyDown,
  1437     {
  1681             aHIDModifiers);
  1438     TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::HandleKeyMapping")));
  1682 
  1439     
  1683     if (!ret)
  1440     TBool ret = EFalse;
  1684         {
  1441     
  1685         ret = HandleMultimediaKeysForStandard(aScancodeKey, aIsKeyDown,
  1442     switch (aKey.iScanCode)
  1686                 aHIDModifiers);
  1443         {
  1687         }
  1444         case EStdKeyUpArrow:
       
  1445             {
       
  1446             ret = HandleKeyMappingUp(aKey, aIsKeyDown, aHIDModifiers);
       
  1447             break;
       
  1448             }
       
  1449         case EStdKeyDownArrow:
       
  1450             {
       
  1451             ret = HandleKeyMappingDown(aKey, aIsKeyDown, aHIDModifiers);
       
  1452             break;
       
  1453             }
       
  1454         case EStdKeyLeftArrow:
       
  1455             {
       
  1456             ret = HandleKeyMappingLeft(aKey, aIsKeyDown, aHIDModifiers);
       
  1457             break;
       
  1458             }
       
  1459         case EStdKeyRightArrow:
       
  1460             {
       
  1461             ret = HandleKeyMappingRight(aKey, aIsKeyDown, aHIDModifiers);
       
  1462             break;
       
  1463             }
       
  1464         case EStdKeyEscape:
       
  1465             // fall through
       
  1466         case EStdKeyF8:
       
  1467             // fall through
       
  1468         case EStdKeyApplication2:
       
  1469             // fall through
       
  1470         case EStdKeyApplication3:
       
  1471             // fall through
       
  1472         case EStdKeyF9:
       
  1473             // break;
       
  1474         case EStdKeyApplication4:
       
  1475             // fall through
       
  1476         case EStdKeyF7:
       
  1477             // fall through
       
  1478         case EStdKeyApplication5:
       
  1479             // fall through
       
  1480         case EStdKeyF12:
       
  1481             // fall through
       
  1482         case EStdKeyIncVolume:
       
  1483             // fall through
       
  1484         case EStdKeyF11:
       
  1485             // fall through
       
  1486         case EStdKeyDecVolume:
       
  1487             // fall through
       
  1488         case EStdKeyF10:
       
  1489             {
       
  1490             ret = HandleKeyMappingOther(aKey, aIsKeyDown, aHIDModifiers);
       
  1491             break;
       
  1492             }
       
  1493         default:
       
  1494             {
       
  1495             // no actions for these keys
       
  1496             break;
       
  1497             }
       
  1498         }
       
  1499     
  1688     return ret;
  1500     return ret;
  1689     }
  1501     }
  1690 
  1502 
  1691 void CHidKeyboardDriver::ResetBitmap(TBool aIsKeyDown,
  1503 // ----------------------------------------------------------------------
  1692         TMmKeyDown aBitmapToReset)
  1504 // CHidKeyboardDriver::HandleKeyMappingUp
  1693     {
  1505 // Handle key mapping gor UP + MODIFIER
  1694     if (aIsKeyDown)
  1506 // ----------------------------------------------------------------------
  1695         {
  1507 //
  1696         iMmKeyDown = (iMmKeyDown | aBitmapToReset);
  1508 TBool CHidKeyboardDriver::HandleKeyMappingUp(TDecodedKeyInfo& aKey,
  1697         }
  1509     TBool aIsKeyDown,
  1698     else
  1510     TUint8 aHIDModifiers)
  1699         {
  1511     {
  1700         iMmKeyDown = (iMmKeyDown & !aBitmapToReset);
  1512     TRACE_INFO((_L("[HID]\tCHidKeyboardDriver::HandleKeyMappingUp")));
  1701         }
  1513     
  1702     }
  1514     TBool ret = EFalse;
  1703 
       
  1704 TBool CHidKeyboardDriver::HandleMultimediaKeysForNokia(TUint16 aScancodeKey,
       
  1705         TBool aIsKeyDown, TUint8 aHIDModifiers)
       
  1706     {
       
  1707     const TUint KHidModifierCtrl = 0x01;
       
  1708     const TUint KHidModifierCtrlRight = 0x10;
       
  1709     const TUint KHidModifierAlt = 0x04;
       
  1710 
       
  1711     //	const TUint KHidModifierAltGr = 0x64;
       
  1712     TInt scancode = 0;
  1515     TInt scancode = 0;
  1713     TUint modifier = 0;
  1516     TUint modifier = 0;
  1714     TBool isMmKey = EFalse;
  1517     TBool isMmKey = EFalse;
  1715 
  1518     TMmKeyDown bitmapToReset = ENone;
  1716     TMmKeyDown bitmapToReset;
  1519     
  1717 
  1520     switch (aKey.iScanCode)
  1718         TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::HandleNokiaMultimediaKeys: scancode 0x%08x, HIDmodifiers 0x%08x"), aScancodeKey, aHIDModifiers));
  1521         {
  1719 
       
  1720     switch (aScancodeKey)
       
  1721         {
       
  1722 
       
  1723         // Mappings for Nokia SU-8W
       
  1724         // Key down events are stored into bitmap in order to detect if keys are released in reverse order, which caused jamming.
       
  1725         // For example: control key released before arrow key.
       
  1726 
       
  1727         case EStdKeyUpArrow:
  1522         case EStdKeyUpArrow:
  1728             {
  1523             {
  1729             if (aHIDModifiers & (KHidModifierCtrl | KHidModifierCtrlRight)
  1524             // Key up and send key was emulated
  1730                     || iMmKeyDown & EVolUp)
  1525             if (!aIsKeyDown &&
  1731                 {
  1526                 iNavKeyDown & ESend)
  1732                 scancode = EStdKeyIncVolume; //Volume Up = Ctrl + ArrowUp
  1527                 {
  1733                 isMmKey = ETrue;
  1528                 TRACE_INFO((_L("[HID]\tCTRL + UP >>> SEND KEY UP")));
  1734                 // Set or reset flag bit
  1529 
  1735 
  1530                 aKey.iScanCode = EStdKeyYes;
  1736                 bitmapToReset = EVolUp;
  1531                 TTranslatedKey& key = aKey.iEvent[0];
  1737                     TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::HandleNokiaMultimediaKeys: Volume up %d"), aIsKeyDown));
  1532                 key.iIsRepeatingKey = aIsKeyDown;
  1738                 }
  1533                 key.iScanCode = EStdKeyYes;
  1739             break;
  1534                 key.iUnicode = EKeyYes;
  1740             }
  1535                 
  1741 
  1536                 iNavKeyDown = (iNavKeyDown & !ESend);
  1742         case EStdKeyDownArrow:
  1537                 }
  1743             {
  1538             
  1744             if (aHIDModifiers & (KHidModifierCtrl | KHidModifierCtrlRight)
  1539             //CTRL = Send key
  1745                     || iMmKeyDown & EVolDown)
  1540             else if (aIsKeyDown &&
  1746                 {
  1541                 aHIDModifiers & (KHidModifierCtrl | KHidModifierCtrlRight))
  1747                 scancode = EStdKeyDecVolume; //Volume Down = Ctrl + ArrowDown
  1542                 {
  1748                 isMmKey = ETrue;
  1543                 TRACE_INFO((_L("[HID]\tCTRL + UP >>> SEND KEY DOWN")));
  1749                 bitmapToReset = EVolDown;
  1544                 
  1750                     TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::HandleNokiaMultimediaKeys: Volume down %d"), aIsKeyDown));
  1545                 aKey.iScanCode = EStdKeyYes;
  1751                 }
  1546                 aKey.iCount = 1;
  1752             break;
  1547                 TTranslatedKey& key = aKey.iEvent[0];
  1753             }
  1548                 key.iIsRepeatingKey = aIsKeyDown;
  1754 
  1549                 key.iScanCode = EStdKeyYes;
  1755         case EStdKeyRightArrow:
  1550                 key.iUnicode = EKeyYes;
  1756             {
  1551                 
  1757             if (aHIDModifiers & KHidModifierAlt || iMmKeyDown & EPlay)
  1552                 iNavKeyDown = (iNavKeyDown | ESend);
  1758                 {
  1553                 }
  1759                 scancode = EStdKeyApplication2; //Play = Alt + ArrowRight
  1554             
  1760                 isMmKey = ETrue;
  1555             //ALT = Stop
  1761                 bitmapToReset = EPlay;
  1556             else if (aHIDModifiers & (KHidModifierAlt | KHidModifierAltRight) ||
  1762 
  1557                 iMmKeyDown & EStop)
  1763                     TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::HandleNokiaMultimediaKeys: Play %d"), aIsKeyDown));
  1558                 {
  1764                 }
  1559                 TRACE_INFO((_L("[HID]\tALT + UP >>> STOP")));
  1765             else if (aHIDModifiers & (KHidModifierCtrl
  1560                 
  1766                     | KHidModifierCtrlRight) || iMmKeyDown & ENext)
  1561                 scancode = EStdKeyApplication3;
  1767                 {
       
  1768                 scancode = EStdKeyApplication4; //Next = Ctrl + ArrowRight
       
  1769                 isMmKey = ETrue;
       
  1770                 bitmapToReset = ENext;
       
  1771                     TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::HandleNokiaMultimediaKeys: Next %d"), aIsKeyDown));
       
  1772                 }
       
  1773             break;
       
  1774             }
       
  1775 
       
  1776         case EStdKeyLeftArrow:
       
  1777             {
       
  1778             if (aHIDModifiers & KHidModifierAlt || iMmKeyDown & EStop)
       
  1779                 {
       
  1780                 scancode = EStdKeyApplication3; //Stop	= Alt + ArrowLeft
       
  1781                 isMmKey = ETrue;
  1562                 isMmKey = ETrue;
  1782                 bitmapToReset = EStop;
  1563                 bitmapToReset = EStop;
  1783                     TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::HandleNokiaMultimediaKeys: Stop %d"), aIsKeyDown));
  1564                 }
  1784                 }
  1565 
  1785             else if (aHIDModifiers & (KHidModifierCtrl
  1566             //SHIFT = Volume up
  1786                     | KHidModifierCtrlRight) || iMmKeyDown & EPrev)
  1567             else if (aHIDModifiers & (KHidModifierShift | KHidModifierShiftRight) ||
  1787                 {
  1568                 iMmKeyDown & EVolUp)
  1788                 scancode = EStdKeyApplication5; //Prev	= Ctrl + ArrowLeft
  1569                 {
       
  1570                 TRACE_INFO((_L("[HID]\tSHIFT + UP >>> VOLUME UP")));
       
  1571                 
       
  1572                 scancode = EStdKeyIncVolume;
  1789                 isMmKey = ETrue;
  1573                 isMmKey = ETrue;
  1790                 bitmapToReset = EPrev;
  1574                 bitmapToReset = EVolUp;
  1791                     TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::HandleNokiaMultimediaKeys: Prev %d"), aIsKeyDown));
  1575                 }
  1792                 }
  1576             break;
  1793             break;
  1577             }
  1794             }
       
  1795 
       
  1796         default:
  1578         default:
  1797             break;
  1579             {
       
  1580             // no actions
       
  1581             break;
       
  1582             }
  1798         }
  1583         }
  1799 
  1584 
  1800     if (isMmKey)
  1585     if (isMmKey)
  1801         {
  1586         {
  1802         ResetBitmap(aIsKeyDown, bitmapToReset);
  1587         if (bitmapToReset)
       
  1588             {
       
  1589             ResetBitmap(aIsKeyDown, bitmapToReset);
       
  1590             }
  1803         SendRawEvent(scancode, aIsKeyDown, modifier);
  1591         SendRawEvent(scancode, aIsKeyDown, modifier);
  1804         }
  1592         ret = ETrue;
  1805     return isMmKey;
  1593         }
  1806     }
  1594     
  1807 
  1595     return ret;
  1808 TBool CHidKeyboardDriver::HandleMultimediaKeysForStandard(
  1596     }
  1809         TUint16 aScancodeKey, TBool aIsKeyDown, TUint8 aHIDModifiers)
  1597 
  1810     {
  1598 // ----------------------------------------------------------------------
       
  1599 // CHidKeyboardDriver::HandleKeyMappingDown
       
  1600 // Handle key mapping gor DOWN + MODIFIER
       
  1601 // ----------------------------------------------------------------------
       
  1602 //
       
  1603 TBool CHidKeyboardDriver::HandleKeyMappingDown(TDecodedKeyInfo& aKey,
       
  1604     TBool aIsKeyDown,
       
  1605     TUint8 aHIDModifiers)
       
  1606     {
       
  1607     TRACE_INFO((_L("[HID]\tCHidKeyboardDriver::HandleKeyMappingDown")));
       
  1608 
       
  1609     TBool ret = EFalse;
  1811     TInt scancode = 0;
  1610     TInt scancode = 0;
  1812     TUint modifier = 0;
  1611     TUint modifier = 0;
  1813     TBool isMmKey = EFalse;
  1612     TBool isMmKey = EFalse;
  1814 
  1613     TMmKeyDown bitmapToReset = ENone;
  1815         TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::HandleNokiaMultimediaKeys: scancode 0x%08x, HIDmodifiers 0x%08x"), aScancodeKey, aHIDModifiers));
  1614     
  1816     //please complier...
  1615     switch (aKey.iScanCode)
  1817     (void) aHIDModifiers;
  1616         {
  1818 
  1617         case EStdKeyDownArrow:
  1819     switch (aScancodeKey)
  1618             {
  1820         {
  1619             // Key up and end key was emulated
  1821         // Mappings for standard keyboards
  1620             if (!aIsKeyDown &&
  1822 
  1621                 iNavKeyDown & EEnd)
  1823         case EStdKeyApplication2: //Play
  1622                 {
  1824             {
  1623                 TRACE_INFO((_L("[HID]\tCTRL + DOWN >>> END KEY UP")));
       
  1624 
       
  1625                 aKey.iScanCode = EStdKeyNo;
       
  1626                 TTranslatedKey& key = aKey.iEvent[0];
       
  1627                 key.iIsRepeatingKey = aIsKeyDown;
       
  1628                 key.iScanCode = EStdKeyNo;
       
  1629                 key.iUnicode = EKeyNo;
       
  1630                 
       
  1631                 iNavKeyDown = (iNavKeyDown & !EEnd);
       
  1632                 }
       
  1633             
       
  1634             //CTRL = End key
       
  1635             else if (aIsKeyDown &&
       
  1636                 aHIDModifiers & (KHidModifierCtrl | KHidModifierCtrlRight))
       
  1637                 {
       
  1638                 TRACE_INFO((_L("[HID]\tCTRL + DOWN >>> END KEY DOWN")));
       
  1639                 
       
  1640                 aKey.iScanCode = EStdKeyNo;
       
  1641                 aKey.iCount = 1;
       
  1642                 TTranslatedKey& key = aKey.iEvent[0];
       
  1643                 key.iIsRepeatingKey = aIsKeyDown;
       
  1644                 key.iScanCode = EStdKeyNo;
       
  1645                 key.iUnicode = EKeyNo;
       
  1646                 
       
  1647                 iNavKeyDown = (iNavKeyDown | EEnd);
       
  1648                 }
       
  1649 
       
  1650             //ALT = Stop
       
  1651             else if (aHIDModifiers & (KHidModifierAlt | KHidModifierAltRight) ||
       
  1652                 iMmKeyDown & EPlay)
       
  1653                 {
       
  1654                 TRACE_INFO((_L("[HID]\tALT + DOWN >>> PLAY / PAUSE")));
       
  1655                 
       
  1656                 scancode = EStdKeyApplication2;
       
  1657                 isMmKey = ETrue;
       
  1658                 bitmapToReset = EPlay;
       
  1659                 }
       
  1660 
       
  1661             //SHIFT = Volume down
       
  1662             else if (aHIDModifiers & (KHidModifierShift | KHidModifierShiftRight) ||
       
  1663                 iMmKeyDown & EVolDown)
       
  1664                 {
       
  1665                 TRACE_INFO((_L("[HID]\tSHIFT + DOWN >>> VOLUME DOWN")));
       
  1666                 
       
  1667                 scancode = EStdKeyDecVolume;
       
  1668                 isMmKey = ETrue;
       
  1669                 bitmapToReset = EVolDown;
       
  1670                 }
       
  1671             break;
       
  1672             }
       
  1673         default:
       
  1674             {
       
  1675             // no actions
       
  1676             break;
       
  1677             }
       
  1678         }
       
  1679 
       
  1680     if (isMmKey)
       
  1681         {
       
  1682         if (bitmapToReset)
       
  1683             {
       
  1684             ResetBitmap(aIsKeyDown, bitmapToReset);
       
  1685             }
       
  1686         SendRawEvent(scancode, aIsKeyDown, modifier);
       
  1687         ret = ETrue;
       
  1688         }
       
  1689     
       
  1690     return ret;
       
  1691     }
       
  1692 
       
  1693 // ----------------------------------------------------------------------
       
  1694 // CHidKeyboardDriver::HandleKeyMappingLeft
       
  1695 // Handle key mapping gor LEFT + MODIFIER
       
  1696 // ----------------------------------------------------------------------
       
  1697 //
       
  1698 TBool CHidKeyboardDriver::HandleKeyMappingLeft(TDecodedKeyInfo& aKey,
       
  1699     TBool aIsKeyDown,
       
  1700     TUint8 aHIDModifiers)
       
  1701     {
       
  1702     TRACE_INFO((_L("[HID]\tCHidKeyboardDriver::HandleKeyMappingLeft")));
       
  1703 
       
  1704     TBool ret = EFalse;
       
  1705     TInt scancode = 0;
       
  1706     TUint modifier = 0;
       
  1707     TBool isMmKey = EFalse;
       
  1708     TMmKeyDown bitmapToReset = ENone;
       
  1709     
       
  1710     switch (aKey.iScanCode)
       
  1711         {
       
  1712         case EStdKeyLeftArrow:
       
  1713             {
       
  1714             // Key up and LSK was simulated
       
  1715             if (!aIsKeyDown &&
       
  1716                 iNavKeyDown & ELsk)
       
  1717                 {
       
  1718                 TRACE_INFO((_L("[HID]\tCTRL + LEFT >>> LEFT SOFTKEY UP")));
       
  1719                 
       
  1720                 aKey.iScanCode = EStdKeyDevice0;
       
  1721                 TTranslatedKey& key = aKey.iEvent[0];
       
  1722                 key.iIsRepeatingKey = aIsKeyDown;
       
  1723                 key.iScanCode = EStdKeyDevice0;
       
  1724                 key.iUnicode = EKeyDevice0;
       
  1725                 
       
  1726                 iNavKeyDown = (iNavKeyDown & !ELsk); 
       
  1727                 }
       
  1728             
       
  1729             //CTRL = LSK
       
  1730             else if (aIsKeyDown &&
       
  1731                 aHIDModifiers & (KHidModifierCtrl | KHidModifierCtrlRight))
       
  1732                 {
       
  1733                 TRACE_INFO((_L("[HID]\tCTRL + LEFT >>> LEFT SOFTKEY DOWN")));
       
  1734                 
       
  1735                 aKey.iScanCode = EStdKeyDevice0;
       
  1736                 aKey.iCount = 1;
       
  1737                 TTranslatedKey& key = aKey.iEvent[0];
       
  1738                 key.iIsRepeatingKey = aIsKeyDown;
       
  1739                 key.iScanCode = EStdKeyDevice0;
       
  1740                 key.iUnicode = EKeyDevice0;
       
  1741                 
       
  1742                 iNavKeyDown = (iNavKeyDown | ELsk);
       
  1743                 }
       
  1744 
       
  1745             //ALT (short) = Previous
       
  1746             //ALT (long) = Backwards
       
  1747             else if (aHIDModifiers & (KHidModifierAlt | KHidModifierAltRight) ||
       
  1748                 iMmKeyDown & EPrev)
       
  1749                 {
       
  1750                 TRACE_INFO((_L("[HID]\tALT + LEFT >>> PREVIOUS / REW")));
       
  1751                 
       
  1752                 scancode = EStdKeyApplication5;
       
  1753                 isMmKey = ETrue;
       
  1754                 bitmapToReset = ENext;
       
  1755                 }
       
  1756 
       
  1757             //SHIFT = Mute toggle
       
  1758             else if (aHIDModifiers & (KHidModifierShift | KHidModifierShiftRight) ||
       
  1759                 iMmKeyDown & EPlay)
       
  1760                 {
       
  1761                 TRACE_INFO((_L("[HID]\tSHIFT + LEFT >>> MUTE / UNMUTE")));
       
  1762                 
       
  1763                 scancode = EStdKeyApplication2;
       
  1764                 isMmKey = ETrue;
       
  1765                 bitmapToReset = EPlay;
       
  1766                 }
       
  1767             break;
       
  1768             }
       
  1769         default:
       
  1770             {
       
  1771             // no actions
       
  1772             break;
       
  1773             }
       
  1774         }
       
  1775 
       
  1776     if (isMmKey)
       
  1777         {
       
  1778         if (bitmapToReset)
       
  1779             {
       
  1780             ResetBitmap(aIsKeyDown, bitmapToReset);
       
  1781             }
       
  1782         SendRawEvent(scancode, aIsKeyDown, modifier);
       
  1783         ret = ETrue;
       
  1784         }
       
  1785     
       
  1786     return ret;
       
  1787     }
       
  1788 
       
  1789 // ----------------------------------------------------------------------
       
  1790 // CHidKeyboardDriver::HandleKeyMappingRight
       
  1791 // Handle key mapping gor RIGHT + MODIFIER
       
  1792 // ----------------------------------------------------------------------
       
  1793 //
       
  1794 TBool CHidKeyboardDriver::HandleKeyMappingRight(TDecodedKeyInfo& aKey,
       
  1795     TBool aIsKeyDown,
       
  1796     TUint8 aHIDModifiers)
       
  1797     {
       
  1798     TRACE_INFO((_L("[HID]\tCHidKeyboardDriver::HandleKeyMappingRight")));
       
  1799 
       
  1800     TBool ret = EFalse;
       
  1801     TInt scancode = 0;
       
  1802     TUint modifier = 0;
       
  1803     TBool isMmKey = EFalse;
       
  1804     TMmKeyDown bitmapToReset = ENone;
       
  1805     
       
  1806     switch (aKey.iScanCode)
       
  1807         {
       
  1808         case EStdKeyRightArrow:
       
  1809             {
       
  1810             // Key up and RSK was simulated
       
  1811             if (!aIsKeyDown &&
       
  1812                 iNavKeyDown & ERsk)
       
  1813                 {
       
  1814                 TRACE_INFO((_L("[HID]\tCTRL + LEFT >>> RIGHT SOFTKEY UP")));
       
  1815                 
       
  1816                 aKey.iScanCode = EStdKeyDevice1;
       
  1817                 TTranslatedKey& key = aKey.iEvent[0];
       
  1818                 key.iIsRepeatingKey = aIsKeyDown;
       
  1819                 key.iScanCode = EStdKeyDevice1;
       
  1820                 key.iUnicode = EKeyDevice1;
       
  1821                 
       
  1822                 iNavKeyDown = (iNavKeyDown & !ERsk); 
       
  1823                 }
       
  1824             
       
  1825             //CTRL = RSK
       
  1826             else if (aIsKeyDown &&
       
  1827                 aHIDModifiers & (KHidModifierCtrl | KHidModifierCtrlRight))
       
  1828                 {
       
  1829                 TRACE_INFO((_L("[HID]\tCTRL + RIGHT >>> RIGHT SOFTKEY DOWN")));
       
  1830                 
       
  1831                 aKey.iScanCode = EStdKeyDevice1;
       
  1832                 aKey.iCount = 1;
       
  1833                 TTranslatedKey& key = aKey.iEvent[0];
       
  1834                 key.iIsRepeatingKey = aIsKeyDown;
       
  1835                 key.iScanCode = EStdKeyDevice1;
       
  1836                 key.iUnicode = EKeyDevice1;
       
  1837                 
       
  1838                 iNavKeyDown = (iNavKeyDown | ERsk);
       
  1839                 }
       
  1840 
       
  1841             //ALT (short) = Next
       
  1842             //ALT (long)  = Forward
       
  1843             else if (aHIDModifiers & (KHidModifierAlt | KHidModifierAltRight) ||
       
  1844                 iMmKeyDown & EPrev)
       
  1845                 {
       
  1846                 TRACE_INFO((_L("[HID]\tALT + RIGHT >>> NEXT / FF")));
       
  1847                 
       
  1848                 scancode = EStdKeyApplication4;
       
  1849                 isMmKey = ETrue;
       
  1850                 bitmapToReset = EPrev;
       
  1851                 }
       
  1852 
       
  1853             //SHIFT = Mute toggle (currently just toggle play / pause)
       
  1854             else if (aHIDModifiers & (KHidModifierShift | KHidModifierShiftRight) ||
       
  1855                 iMmKeyDown & EPlay)
       
  1856                 {
       
  1857                 TRACE_INFO((_L("[HID]\tSHIFT + RIGHT >>> MUTE / UNMUTE")));
       
  1858                 
       
  1859                 scancode = EStdKeyApplication2;
       
  1860                 isMmKey = ETrue;
       
  1861                 bitmapToReset = EPlay;
       
  1862                 }
       
  1863             break;
       
  1864             }
       
  1865         default:
       
  1866             {
       
  1867             // no actions
       
  1868             break;
       
  1869             }
       
  1870         }
       
  1871 
       
  1872     if (isMmKey)
       
  1873         {
       
  1874         if (bitmapToReset)
       
  1875             {
       
  1876             ResetBitmap(aIsKeyDown, bitmapToReset);
       
  1877             }
       
  1878         SendRawEvent(scancode, aIsKeyDown, modifier);
       
  1879         ret = ETrue;
       
  1880         }
       
  1881     
       
  1882     return ret;
       
  1883     }
       
  1884 
       
  1885 // ----------------------------------------------------------------------
       
  1886 // CHidKeyboardDriver::HandleKeyMappingOther
       
  1887 // Handle key mapping gor OTHER + MODIFIER
       
  1888 // ----------------------------------------------------------------------
       
  1889 //
       
  1890 TBool CHidKeyboardDriver::HandleKeyMappingOther(TDecodedKeyInfo& aKey,
       
  1891     TBool aIsKeyDown,
       
  1892     TUint8 /*aHIDModifiers*/)
       
  1893     {
       
  1894     TRACE_INFO((_L("[HID]\tCHidKeyboardDriver::HandleKeyMappingOther")));
       
  1895 
       
  1896     TBool ret = EFalse;
       
  1897     TInt scancode = 0;
       
  1898     TUint modifier = 0;
       
  1899     TBool isMmKey = EFalse;
       
  1900     
       
  1901     switch (aKey.iScanCode)
       
  1902         {
       
  1903         case EStdKeyEscape:
       
  1904             {
       
  1905             // ESC is released and keys were locked, eat the key press
       
  1906             if (!aIsKeyDown &&
       
  1907                 iNavKeyDown & EEsc)
       
  1908                 {
       
  1909                 TRACE_INFO((_L("[HID]\tESC >>> DISBALE KEY LOCK UP")));
       
  1910                 
       
  1911                 ret = ETrue;
       
  1912                 iNavKeyDown = (iNavKeyDown & !EEsc);
       
  1913                 }
       
  1914             
       
  1915             // ESC when keylock enabled >>> Disabled key lock
       
  1916 /*            else if (aIsKeyDown &&
       
  1917                 iKeyLock.IsKeyLockEnabled())
       
  1918                 {
       
  1919                 TRACE_INFO((_L("[HID]\tESC >>> DISBALE KEY LOCK DOWN")));
       
  1920                 
       
  1921                 iKeyLock.DisableKeyLock();
       
  1922 
       
  1923                 ret = ETrue;
       
  1924                 iNavKeyDown = (iNavKeyDown | EEsc);
       
  1925                 }
       
  1926 */
       
  1927             break;
       
  1928             }
       
  1929         case EStdKeyF8:
       
  1930             // fall through
       
  1931         case EStdKeyApplication2:
       
  1932             {
       
  1933             TRACE_INFO((_L("[HID]\tF8 / APPLICATION2 >>> PLAY / PAUSE")));
       
  1934             
       
  1935             // PLAY / PAUSE
       
  1936             if (aKey.iScanCode != EStdKeyApplication2)
       
  1937                 {
       
  1938                 scancode = EStdKeyApplication2;
       
  1939                 isMmKey = ETrue;
       
  1940                 }
       
  1941             break;
       
  1942             }
       
  1943         case EStdKeyApplication3:
       
  1944             {
       
  1945             TRACE_INFO((_L("[HID]\tAPPLICATION3 >>> STOP")));
       
  1946             
       
  1947             // STOP
       
  1948             scancode = EStdKeyApplication3;
       
  1949             isMmKey = ETrue;
       
  1950             break;
       
  1951             }
       
  1952         case EStdKeyF9:
       
  1953             // break;
       
  1954         case EStdKeyApplication4:
       
  1955             {
       
  1956             TRACE_INFO((_L("[HID]\tF9 / APPLICATION4 >>> NEXT / FF")));
       
  1957             
       
  1958             // NEXT
       
  1959             scancode = EStdKeyApplication4;
       
  1960             isMmKey = ETrue;
       
  1961             break;
       
  1962             }
       
  1963         case EStdKeyF7:
       
  1964             // fall through
       
  1965         case EStdKeyApplication5:
       
  1966             {
       
  1967             TRACE_INFO((_L("[HID]\tF7 / APPLICATION5 >>> PREVIOUS / REW")));
       
  1968             
       
  1969             // PREVIOUS
       
  1970             scancode = EStdKeyApplication5;
       
  1971             isMmKey = ETrue;
       
  1972             break;
       
  1973             }
       
  1974         case EStdKeyF12:
       
  1975             // fall through
       
  1976         case EStdKeyIncVolume:
       
  1977             {
       
  1978             TRACE_INFO((_L("[HID]\tF12 / INCVOLUME >>> VOLUME UP")));
       
  1979             
       
  1980             // VOLUME UP
       
  1981             scancode = EStdKeyIncVolume;
       
  1982             isMmKey = ETrue;
       
  1983             break;
       
  1984             }
       
  1985         case EStdKeyF11:
       
  1986             // fall through
       
  1987         case EStdKeyDecVolume:
       
  1988             {
       
  1989             TRACE_INFO((_L("[HID]\tF11 / DECVOLUME >>> VOLUME DOWN")));
       
  1990             
       
  1991             // VOLUME DOWN
       
  1992             scancode = EStdKeyDecVolume;
       
  1993             isMmKey = ETrue;
       
  1994             break;
       
  1995             }
       
  1996         case EStdKeyF10:
       
  1997             {
       
  1998             TRACE_INFO((_L("[HID]\tF10 >>> MUTE")));
       
  1999             
       
  2000             // MUTE (currently just toggle play / pause)
  1825             scancode = EStdKeyApplication2;
  2001             scancode = EStdKeyApplication2;
  1826             isMmKey = ETrue;
  2002             isMmKey = ETrue;
  1827                 TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::HandleNokiaMultimediaKeys: Play %d"), aIsKeyDown));
  2003             break;
  1828             break;
  2004             }
  1829             }
       
  1830 
       
  1831         case EStdKeyApplication3: //Stop
       
  1832             {
       
  1833             scancode = EStdKeyApplication3;
       
  1834             isMmKey = ETrue;
       
  1835                 TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::HandleNokiaMultimediaKeys: Stop %d"), aIsKeyDown));
       
  1836             break;
       
  1837             }
       
  1838 
       
  1839         case EStdKeyApplication4: //Next
       
  1840             {
       
  1841             scancode = EStdKeyApplication4;
       
  1842             isMmKey = ETrue;
       
  1843                 TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::HandleNokiaMultimediaKeys: Next %d"), aIsKeyDown));
       
  1844             break;
       
  1845             }
       
  1846 
       
  1847         case EStdKeyApplication5: //Prev
       
  1848             {
       
  1849             scancode = EStdKeyApplication5;
       
  1850             isMmKey = ETrue;
       
  1851                 TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::HandleNokiaMultimediaKeys: Prev %d"), aIsKeyDown));
       
  1852             break;
       
  1853             }
       
  1854 
       
  1855         case EStdKeyIncVolume: //Volume up
       
  1856             {
       
  1857             scancode = EStdKeyIncVolume;
       
  1858             isMmKey = ETrue;
       
  1859                 TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::HandleNokiaMultimediaKeys: Volume up %d"), aIsKeyDown));
       
  1860             break;
       
  1861             }
       
  1862 
       
  1863         case EStdKeyDecVolume: //Volume down
       
  1864             {
       
  1865             scancode = EStdKeyDecVolume;
       
  1866             isMmKey = ETrue;
       
  1867                 TRACE_INFO( (_L("[HID]\tCHidKeyboardDriver::HandleNokiaMultimediaKeys: Volume down %d"), aIsKeyDown));
       
  1868             break;
       
  1869             }
       
  1870 
       
  1871         default:
  2005         default:
  1872             break;
  2006             {
       
  2007             break;
       
  2008             }
  1873         }
  2009         }
  1874 
  2010 
  1875     if (isMmKey)
  2011     if (isMmKey)
  1876         {
  2012         {
  1877         SendRawEvent(scancode, aIsKeyDown, modifier);
  2013         SendRawEvent(scancode, aIsKeyDown, modifier);
  1878         }
  2014         ret = ETrue;
  1879     return isMmKey;
  2015         }
       
  2016     
       
  2017     return ret;
       
  2018     }
       
  2019 
       
  2020 void CHidKeyboardDriver::ResetBitmap(TBool aIsKeyDown,
       
  2021         TMmKeyDown aBitmapToReset)
       
  2022     {
       
  2023     if (aIsKeyDown)
       
  2024         {
       
  2025         iMmKeyDown = (iMmKeyDown | aBitmapToReset);
       
  2026         }
       
  2027     else
       
  2028         {
       
  2029         iMmKeyDown = (iMmKeyDown & !aBitmapToReset);
       
  2030         }
  1880     }
  2031     }
  1881 
  2032 
  1882 // ----------------------------------------------------------------------
  2033 // ----------------------------------------------------------------------
  1883 // CHidKeyboardDriver::SendRawEvent
  2034 // CHidKeyboardDriver::SendRawEvent
  1884 // Send raw key event to window server
  2035 // Send raw key event to window server
  1935     {
  2086     {
  1936     DBG(RDebug::Print(_L("[HID]\tCHidKeyboardDriver::TimerExpired, cancel all key presses")));
  2087     DBG(RDebug::Print(_L("[HID]\tCHidKeyboardDriver::TimerExpired, cancel all key presses")));
  1937     CancelAllKeys();
  2088     CancelAllKeys();
  1938     }
  2089     }
  1939 
  2090 
  1940 void CHidKeyboardDriver::CursorRedraw()
       
  1941     {
       
  1942     TInt mouseStatus;
       
  1943 
       
  1944     TInt err = RProperty::Get( KPSUidBthidSrv, KBTMouseCursorState, mouseStatus );
       
  1945     if ( !err )
       
  1946         {
       
  1947         err = RProperty::Set( KPSUidBthidSrv, KBTMouseCursorState, ECursorRedraw );
       
  1948         DBG(RDebug::Print(
       
  1949              _L("[BTHID]\tCHidKeyboardDriver::CursorRedraw() X->ECursorRedraw") ) );
       
  1950         }
       
  1951     }
       
  1952 
       
  1953 // ----------------------------------------------------------------------
  2091 // ----------------------------------------------------------------------
  1954 // End of file
  2092 // End of file