qtmobileextensions/src/keycapture/keymapper.cpp
changeset 24 9d760f716ca8
parent 19 46686fb6258c
equal deleted inserted replaced
19:46686fb6258c 24:9d760f716ca8
    23 // TODO: this file is only tempral while we wait for Qt patch approval and include
    23 // TODO: this file is only tempral while we wait for Qt patch approval and include
    24 // 
    24 // 
    25  
    25  
    26 #include "keymapper.h"
    26 #include "keymapper.h"
    27 #include <e32keys.h>
    27 #include <e32keys.h>
       
    28 using namespace Qt;
       
    29 
       
    30 static const KeyMapping keyMapping[] = {
       
    31     {EKeyBackspace, EStdKeyBackspace, Key_Backspace},
       
    32     {EKeyTab, EStdKeyTab, Key_Tab},
       
    33     {EKeyEnter, EStdKeyEnter, Key_Enter},
       
    34     {EKeyEscape, EStdKeyEscape, Key_Escape},
       
    35     {EKeySpace, EStdKeySpace, Key_Space},
       
    36     {EKeyDelete, EStdKeyDelete, Key_Delete},
       
    37     {EKeyPrintScreen, EStdKeyPrintScreen, Key_SysReq},
       
    38     {EKeyPause, EStdKeyPause, Key_Pause},
       
    39     {EKeyHome, EStdKeyHome, Key_Home},
       
    40     {EKeyEnd, EStdKeyEnd, Key_End},
       
    41     {EKeyPageUp, EStdKeyPageUp, Key_PageUp},
       
    42     {EKeyPageDown, EStdKeyPageDown, Key_PageDown},
       
    43     {EKeyInsert, EStdKeyInsert, Key_Insert},
       
    44     {EKeyLeftArrow, EStdKeyLeftArrow, Key_Left},
       
    45     {EKeyRightArrow, EStdKeyRightArrow, Key_Right},
       
    46     {EKeyUpArrow, EStdKeyUpArrow, Key_Up},
       
    47     {EKeyDownArrow, EStdKeyDownArrow, Key_Down},
       
    48     {EKeyLeftShift, EStdKeyLeftShift, Key_Shift},
       
    49     {EKeyRightShift, EStdKeyRightShift, Key_Shift},
       
    50     {EKeyLeftAlt, EStdKeyLeftAlt, Key_Alt},
       
    51     {EKeyRightAlt, EStdKeyRightAlt, Key_AltGr},
       
    52     {EKeyLeftCtrl, EStdKeyLeftCtrl, Key_Control},
       
    53     {EKeyRightCtrl, EStdKeyRightCtrl, Key_Control},
       
    54     {EKeyLeftFunc, EStdKeyLeftFunc, Key_Super_L},
       
    55     {EKeyRightFunc, EStdKeyRightFunc, Key_Super_R},
       
    56     {EKeyCapsLock, EStdKeyCapsLock, Key_CapsLock},
       
    57     {EKeyNumLock, EStdKeyNumLock, Key_NumLock},
       
    58     {EKeyScrollLock, EStdKeyScrollLock, Key_ScrollLock},
       
    59     {EKeyF1, EStdKeyF1, Key_F1},
       
    60     {EKeyF2, EStdKeyF2, Key_F2},
       
    61     {EKeyF3, EStdKeyF3, Key_F3},
       
    62     {EKeyF4, EStdKeyF4, Key_F4},
       
    63     {EKeyF5, EStdKeyF5, Key_F5},
       
    64     {EKeyF6, EStdKeyF6, Key_F6},
       
    65     {EKeyF7, EStdKeyF7, Key_F7},
       
    66     {EKeyF8, EStdKeyF8, Key_F8},
       
    67     {EKeyF9, EStdKeyF9, Key_F9},
       
    68     {EKeyF10, EStdKeyF10, Key_F10},
       
    69     {EKeyF11, EStdKeyF11, Key_F11},
       
    70     {EKeyF12, EStdKeyF12, Key_F12},
       
    71     {EKeyF13, EStdKeyF13, Key_F13},
       
    72     {EKeyF14, EStdKeyF14, Key_F14},
       
    73     {EKeyF15, EStdKeyF15, Key_F15},
       
    74     {EKeyF16, EStdKeyF16, Key_F16},
       
    75     {EKeyF17, EStdKeyF17, Key_F17},
       
    76     {EKeyF18, EStdKeyF18, Key_F18},
       
    77     {EKeyF19, EStdKeyF19, Key_F19},
       
    78     {EKeyF20, EStdKeyF20, Key_F20},
       
    79     {EKeyF21, EStdKeyF21, Key_F21},
       
    80     {EKeyF22, EStdKeyF22, Key_F22},
       
    81     {EKeyF23, EStdKeyF23, Key_F23},
       
    82     {EKeyF24, EStdKeyF24, Key_F24},
       
    83     {EKeyOff, EStdKeyOff, Key_PowerOff},
       
    84 //    {EKeyMenu, EStdKeyMenu, Key_Menu}, // Menu is EKeyApplication0
       
    85     {EKeyHelp, EStdKeyHelp, Key_Help},
       
    86     {EKeyDial, EStdKeyDial, Key_Call},
       
    87     {EKeyIncVolume, EStdKeyIncVolume, Key_VolumeUp},
       
    88     {EKeyDecVolume, EStdKeyDecVolume, Key_VolumeDown},
       
    89     {EKeyDevice0, EStdKeyDevice0, Key_Context1}, // Found by manual testing.
       
    90     {EKeyDevice1, EStdKeyDevice1, Key_Context2}, // Found by manual testing.
       
    91     {EKeyDevice3, EStdKeyDevice3, Key_Select},
       
    92     {EKeyDevice7, EStdKeyDevice7, Key_Camera},  
       
    93     {EKeyApplication0, EStdKeyApplication0, Key_Menu}, // Found by manual testing.
       
    94     {EKeyApplication1, EStdKeyApplication1, Key_Launch1}, // Found by manual testing.
       
    95     {EKeyApplication2, EStdKeyApplication2, Key_MediaPlay}, // Found by manual testing.
       
    96     {EKeyApplication3, EStdKeyApplication3, Key_MediaStop}, // Found by manual testing.
       
    97     {EKeyApplication4, EStdKeyApplication4, Key_MediaNext}, // Found by manual testing.
       
    98     {EKeyApplication5, EStdKeyApplication5, Key_MediaPrevious}, // Found by manual testing.
       
    99     {EKeyApplication6, EStdKeyApplication6, Key_Launch6},
       
   100     {EKeyApplication7, EStdKeyApplication7, Key_Launch7},
       
   101     {EKeyApplication8, EStdKeyApplication8, Key_Launch8},
       
   102     {EKeyApplication9, EStdKeyApplication9, Key_Launch9},
       
   103     {EKeyApplicationA, EStdKeyApplicationA, Key_LaunchA},
       
   104     {EKeyApplicationB, EStdKeyApplicationB, Key_LaunchB},
       
   105     {EKeyApplicationC, EStdKeyApplicationC, Key_LaunchC},
       
   106     {EKeyApplicationD, EStdKeyApplicationD, Key_LaunchD},
       
   107     {EKeyApplicationE, EStdKeyApplicationE, Key_LaunchE},
       
   108     {EKeyApplicationF, EStdKeyApplicationF, Key_LaunchF},
       
   109     {EKeyApplication19, EStdKeyApplication19, Key_CameraFocus}, 
       
   110     {EKeyYes, EStdKeyYes, Key_Yes},
       
   111     {EKeyNo, EStdKeyNo, Key_No},
       
   112     {TKeyCode(0), TStdScanCode(0), Qt::Key(0)}
       
   113 };
    28 
   114 
    29 QKeyMapper::QKeyMapper()
   115 QKeyMapper::QKeyMapper()
    30 {
   116 {
    31     fillKeyMap();
   117    // fillKeyMap();
    32 }
   118 }
    33 
   119 
    34 QKeyMapper::~QKeyMapper()
   120 QKeyMapper::~QKeyMapper()
    35 {
   121 {
    36 }
   122 }
    37 
   123 
    38 void QKeyMapper::fillKeyMap()
       
    39 {
       
    40     using namespace Qt;
       
    41     keyMapping.append(KeyMapping(EKeyBackspace, EStdKeyBackspace, Key_Backspace));
       
    42     keyMapping.append(KeyMapping(EKeyTab, EStdKeyTab, Key_Tab));
       
    43     keyMapping.append(KeyMapping(EKeyEnter, EStdKeyEnter, Key_Enter));
       
    44     keyMapping.append(KeyMapping(EKeyEscape, EStdKeyEscape, Key_Escape));
       
    45     keyMapping.append(KeyMapping(EKeySpace, EStdKeySpace, Key_Space));
       
    46     keyMapping.append(KeyMapping(EKeyDelete, EStdKeyDelete, Key_Delete));
       
    47     keyMapping.append(KeyMapping(EKeyPrintScreen, EStdKeyPrintScreen, Key_SysReq));
       
    48     keyMapping.append(KeyMapping(EKeyPause, EStdKeyPause, Key_Pause));
       
    49     keyMapping.append(KeyMapping(EKeyHome, EStdKeyHome, Key_Home));
       
    50     keyMapping.append(KeyMapping(EKeyEnd, EStdKeyEnd, Key_End));
       
    51     keyMapping.append(KeyMapping(EKeyPageUp, EStdKeyPageUp, Key_PageUp));
       
    52     keyMapping.append(KeyMapping(EKeyPageDown, EStdKeyPageDown, Key_PageDown));
       
    53     keyMapping.append(KeyMapping(EKeyInsert, EStdKeyInsert, Key_Insert));
       
    54     keyMapping.append(KeyMapping(EKeyLeftArrow, EStdKeyLeftArrow, Key_Left));
       
    55     keyMapping.append(KeyMapping(EKeyRightArrow, EStdKeyRightArrow, Key_Right));
       
    56     keyMapping.append(KeyMapping(EKeyUpArrow, EStdKeyUpArrow, Key_Up));
       
    57     keyMapping.append(KeyMapping(EKeyDownArrow, EStdKeyDownArrow, Key_Down));
       
    58     keyMapping.append(KeyMapping(EKeyLeftShift, EStdKeyLeftShift, Key_Shift));
       
    59     keyMapping.append(KeyMapping(EKeyRightShift, EStdKeyRightShift, Key_Shift));
       
    60     keyMapping.append(KeyMapping(EKeyLeftAlt, EStdKeyLeftAlt, Key_Alt));
       
    61     keyMapping.append(KeyMapping(EKeyRightAlt, EStdKeyRightAlt, Key_AltGr));
       
    62     keyMapping.append(KeyMapping(EKeyLeftCtrl, EStdKeyLeftCtrl, Key_Control));
       
    63     keyMapping.append(KeyMapping(EKeyRightCtrl, EStdKeyRightCtrl, Key_Control));
       
    64     keyMapping.append(KeyMapping(EKeyLeftFunc, EStdKeyLeftFunc, Key_Super_L));
       
    65     keyMapping.append(KeyMapping(EKeyRightFunc, EStdKeyRightFunc, Key_Super_R));
       
    66     keyMapping.append(KeyMapping(EKeyCapsLock, EStdKeyCapsLock, Key_CapsLock));
       
    67     keyMapping.append(KeyMapping(EKeyNumLock, EStdKeyNumLock, Key_NumLock));
       
    68     keyMapping.append(KeyMapping(EKeyScrollLock, EStdKeyScrollLock, Key_ScrollLock));
       
    69     keyMapping.append(KeyMapping(EKeyF1, EStdKeyF1, Key_F1));
       
    70     keyMapping.append(KeyMapping(EKeyF2, EStdKeyF2, Key_F2));
       
    71     keyMapping.append(KeyMapping(EKeyF3, EStdKeyF3, Key_F3));
       
    72     keyMapping.append(KeyMapping(EKeyF4, EStdKeyF4, Key_F4));
       
    73     keyMapping.append(KeyMapping(EKeyF5, EStdKeyF5, Key_F5));
       
    74     keyMapping.append(KeyMapping(EKeyF6, EStdKeyF6, Key_F6));
       
    75     keyMapping.append(KeyMapping(EKeyF7, EStdKeyF7, Key_F7));
       
    76     keyMapping.append(KeyMapping(EKeyF8, EStdKeyF8, Key_F8));
       
    77     keyMapping.append(KeyMapping(EKeyF9, EStdKeyF9, Key_F9));
       
    78     keyMapping.append(KeyMapping(EKeyF10, EStdKeyF10, Key_F10));
       
    79     keyMapping.append(KeyMapping(EKeyF11, EStdKeyF11, Key_F11));
       
    80     keyMapping.append(KeyMapping(EKeyF12, EStdKeyF12, Key_F12));
       
    81     keyMapping.append(KeyMapping(EKeyF13, EStdKeyF13, Key_F13));
       
    82     keyMapping.append(KeyMapping(EKeyF14, EStdKeyF14, Key_F14));
       
    83     keyMapping.append(KeyMapping(EKeyF15, EStdKeyF15, Key_F15));
       
    84     keyMapping.append(KeyMapping(EKeyF16, EStdKeyF16, Key_F16));
       
    85     keyMapping.append(KeyMapping(EKeyF17, EStdKeyF17, Key_F17));
       
    86     keyMapping.append(KeyMapping(EKeyF18, EStdKeyF18, Key_F18));
       
    87     keyMapping.append(KeyMapping(EKeyF19, EStdKeyF19, Key_F19));
       
    88     keyMapping.append(KeyMapping(EKeyF20, EStdKeyF20, Key_F20));
       
    89     keyMapping.append(KeyMapping(EKeyF21, EStdKeyF21, Key_F21));
       
    90     keyMapping.append(KeyMapping(EKeyF22, EStdKeyF22, Key_F22));
       
    91     keyMapping.append(KeyMapping(EKeyF23, EStdKeyF23, Key_F23));
       
    92     keyMapping.append(KeyMapping(EKeyF24, EStdKeyF24, Key_F24));
       
    93     keyMapping.append(KeyMapping(EKeyOff, EStdKeyOff, Key_PowerOff));
       
    94 //    keyMapping.append(KeyMapping(EKeyMenu, EStdKeyMenu, Key_Menu)); // Menu is EKeyApplication0
       
    95     keyMapping.append(KeyMapping(EKeyHelp, EStdKeyHelp, Key_Help));
       
    96     keyMapping.append(KeyMapping(EKeyDial, EStdKeyDial, Key_Call));
       
    97     keyMapping.append(KeyMapping(EKeyIncVolume, EStdKeyIncVolume, Key_VolumeUp));
       
    98     keyMapping.append(KeyMapping(EKeyDecVolume, EStdKeyDecVolume, Key_VolumeDown));
       
    99     keyMapping.append(KeyMapping(EKeyDevice0, EStdKeyDevice0, Key_Context1)); // Found by manual testing.
       
   100     keyMapping.append(KeyMapping(EKeyDevice1, EStdKeyDevice1, Key_Context2)); // Found by manual testing.
       
   101     keyMapping.append(KeyMapping(EKeyDevice3, EStdKeyDevice3, Key_Select));
       
   102 //    keyMapping.append(KeyMapping(EKeyDevice7, EStdKeyDevice7, Key_Camera));  //not supported by qt yet
       
   103     keyMapping.append(KeyMapping(EKeyApplication0, EStdKeyApplication0, Key_Menu)); // Found by manual testing.
       
   104     keyMapping.append(KeyMapping(EKeyApplication1, EStdKeyApplication1, Key_Launch1)); // Found by manual testing.
       
   105     keyMapping.append(KeyMapping(EKeyApplication2, EStdKeyApplication2, Key_MediaPlay)); // Found by manual testing.
       
   106     keyMapping.append(KeyMapping(EKeyApplication3, EStdKeyApplication3, Key_MediaStop)); // Found by manual testing.
       
   107     keyMapping.append(KeyMapping(EKeyApplication4, EStdKeyApplication4, Key_MediaNext)); // Found by manual testing.
       
   108     keyMapping.append(KeyMapping(EKeyApplication5, EStdKeyApplication5, Key_MediaPrevious)); // Found by manual testing.
       
   109     keyMapping.append(KeyMapping(EKeyApplication6, EStdKeyApplication6, Key_Launch6));
       
   110     keyMapping.append(KeyMapping(EKeyApplication7, EStdKeyApplication7, Key_Launch7));
       
   111     keyMapping.append(KeyMapping(EKeyApplication8, EStdKeyApplication8, Key_Launch8));
       
   112     keyMapping.append(KeyMapping(EKeyApplication9, EStdKeyApplication9, Key_Launch9));
       
   113     keyMapping.append(KeyMapping(EKeyApplicationA, EStdKeyApplicationA, Key_LaunchA));
       
   114     keyMapping.append(KeyMapping(EKeyApplicationB, EStdKeyApplicationB, Key_LaunchB));
       
   115     keyMapping.append(KeyMapping(EKeyApplicationC, EStdKeyApplicationC, Key_LaunchC));
       
   116     keyMapping.append(KeyMapping(EKeyApplicationD, EStdKeyApplicationD, Key_LaunchD));
       
   117     keyMapping.append(KeyMapping(EKeyApplicationE, EStdKeyApplicationE, Key_LaunchE));
       
   118     keyMapping.append(KeyMapping(EKeyApplicationF, EStdKeyApplicationF, Key_LaunchF));
       
   119 //    keyMapping.append(KeyMapping(EKeyApplication19, EStdKeyApplication19, Key_CameraFocus));  //not supported by qt yet
       
   120     keyMapping.append(KeyMapping(EKeyYes, EStdKeyYes, Key_Yes));
       
   121     keyMapping.append(KeyMapping(EKeyNo, EStdKeyNo, Key_No));    	
       
   122 }
       
   123 
       
   124 int QKeyMapper::mapS60KeyToQt(TUint s60key)
   124 int QKeyMapper::mapS60KeyToQt(TUint s60key)
   125 {
   125 {
   126 	int res = Qt::Key_unknown;
   126     int res = Qt::Key_unknown;
   127 	for ( int i = 0, size = keyMapping.count(); i<size; i++){
   127     for (int i = 0; keyMapping[i].s60KeyCode != 0; i++) {
   128 		if ( keyMapping[i].s60KeyCode == s60key){
   128         if (keyMapping[i].s60KeyCode == s60key) {
   129 			res = keyMapping[i].qtKey;
   129             res = keyMapping[i].qtKey;
   130 			break;
   130             break;
   131 		}
   131         }
   132 	}
   132     }
   133 	return res;
   133     return res;
   134 }
   134 }
   135 
   135 
   136 int QKeyMapper::mapS60ScanCodesToQt(TUint s60scanCode)
   136 int QKeyMapper::mapS60ScanCodesToQt(TUint s60scanCode)
   137 {
   137 {
   138 	int res = Qt::Key_unknown;
   138     int res = Qt::Key_unknown;
   139 	for ( int i = 0, size = keyMapping.count(); i<size; i++){
   139     for (int i = 0; keyMapping[i].s60KeyCode != 0; i++) {
   140 		if ( keyMapping[i].s60ScanCode == s60scanCode){
   140         if (keyMapping[i].s60ScanCode == s60scanCode) {
   141 			res = keyMapping[i].qtKey;
   141             res = keyMapping[i].qtKey;
   142 			break;
   142             break;
   143 		}
   143         }
   144 	}
   144     }
   145 	return res;
   145     return res;
   146 }
   146 }
   147 
   147 
   148 int QKeyMapper::mapQtToS60Key(int qtKey)
   148 int QKeyMapper::mapQtToS60Key(int qtKey)
   149 {
   149 {
   150     int res = KErrUnknown;
   150     int res = KErrUnknown;
   151 	for ( int i = 0, size = keyMapping.count(); i<size; i++){
   151     for (int i = 0; keyMapping[i].s60KeyCode != 0; i++) {
   152 		if ( keyMapping[i].qtKey == qtKey){
   152         if (keyMapping[i].qtKey == qtKey) {
   153 			res = keyMapping[i].s60KeyCode;
   153             res = keyMapping[i].s60KeyCode;
   154 			break;
   154             break;
   155 		}
   155         }
   156 	}
   156     }
   157 	return res;
   157     return res;
   158 }
   158 }
   159 
   159 
   160 int QKeyMapper::mapQtToS60ScanCodes(int qtKey)
   160 int QKeyMapper::mapQtToS60ScanCodes(int qtKey)
   161 {
   161 {
   162 	int res = KErrUnknown;
   162     int res = KErrUnknown;
   163 	for ( int i = 0, size = keyMapping.count(); i<size; i++){
   163     for (int i = 0; keyMapping[i].s60KeyCode != 0; i++) {
   164 		if ( keyMapping[i].qtKey == qtKey){
   164         if (keyMapping[i].qtKey == qtKey) {
   165 			res = keyMapping[i].s60ScanCode;
   165             res = keyMapping[i].s60ScanCode;
   166 			break;
   166             break;
   167 		}
   167         }
   168 	}
   168     }
   169 	return res;
   169     return res;
   170 }
   170 }