|
1 // input.cpp |
|
2 // |
|
3 // Copyright (c) 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "Eclipse Public License v1.0" |
|
6 // which accompanies this distribution, and is available |
|
7 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 // |
|
9 // Initial Contributors: |
|
10 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #include <e32keys.h> |
|
14 #include <fshell/ioutils.h> |
|
15 #include <fshell/common.mmh> |
|
16 #include <fshell/ltkutils.h> |
|
17 |
|
18 using namespace IoUtils; |
|
19 |
|
20 |
|
21 class TKeyMapping |
|
22 { |
|
23 public: |
|
24 TUint16 iConsoleKey; |
|
25 TUint16 iScanCode; |
|
26 TUint16 iModifiers; |
|
27 #ifdef __WINS__ |
|
28 const TText* iLabel; |
|
29 #else |
|
30 const wchar_t* iLabel; |
|
31 #endif |
|
32 }; |
|
33 |
|
34 const TKeyMapping KKeyMappings[] = |
|
35 { |
|
36 { '0', '0', 0, L"Zero" }, |
|
37 { '1', '1', 0, L"One" }, |
|
38 { '2', '2', 0, L"Two" }, |
|
39 { '3', '3', 0, L"Three" }, |
|
40 { '4', '4', 0, L"Four" }, |
|
41 { '5', '5', 0, L"Five" }, |
|
42 { '6', '6', 0, L"Six" }, |
|
43 { '7', '7', 0, L"Seven" }, |
|
44 { '8', '8', 0, L"Eight" }, |
|
45 { '9', '9', 0, L"Nine" }, |
|
46 { '*', '*', 0, L"Star" }, |
|
47 { '#', '#', 0, L"Hash" }, |
|
48 { EKeyUpArrow, EStdKeyUpArrow, 0, L"Up" }, |
|
49 { EKeyDownArrow, EStdKeyDownArrow, 0, L"Down" }, |
|
50 { EKeyLeftArrow, EStdKeyLeftArrow, 0, L"Left" }, |
|
51 { EKeyRightArrow, EStdKeyRightArrow, 0, L"Right" }, |
|
52 #ifdef LTK_PLATFORM_DCM |
|
53 { EKeyEnter, 167, 0, L"Enter" }, |
|
54 { 'o', 164, 0, L"Menu" }, |
|
55 { 'p', 165, 0, L"Camera" }, |
|
56 { 'l', 228, 0, L"Mail" }, |
|
57 { ';', 229, 0, L"IMode" }, |
|
58 { ',', 196, 0, L"Call" }, |
|
59 { '.', EStdKeyBackspace, 0, L"Clear" }, |
|
60 { '/', 197, 0, L"End" }, |
|
61 { 'm', 230, 0, L"Multi" }, |
|
62 #endif |
|
63 }; |
|
64 const TInt KNumKeyMappings = sizeof(KKeyMappings) / sizeof(TKeyMapping); |
|
65 |
|
66 |
|
67 class CCmdInput : public CCommandBase |
|
68 { |
|
69 public: |
|
70 static CCommandBase* NewLC(); |
|
71 ~CCmdInput(); |
|
72 private: |
|
73 CCmdInput(); |
|
74 void ShowKeyMappings(); |
|
75 void SimulateKeyL(TInt aConsoleKey); |
|
76 private: // From CCommandBase. |
|
77 virtual const TDesC& Name() const; |
|
78 virtual void DoRunL(); |
|
79 virtual void ArgumentsL(RCommandArgumentList& aArguments); |
|
80 virtual void OptionsL(RCommandOptionList& aOptions); |
|
81 private: |
|
82 TUint iConsoleKey; |
|
83 TBool iShow; |
|
84 TUint iScanCode; |
|
85 TUint iModifiers; |
|
86 }; |
|
87 |
|
88 EXE_BOILER_PLATE(CCmdInput) |
|
89 |
|
90 CCommandBase* CCmdInput::NewLC() |
|
91 { |
|
92 CCmdInput* self = new(ELeave) CCmdInput(); |
|
93 CleanupStack::PushL(self); |
|
94 self->BaseConstructL(); |
|
95 return self; |
|
96 } |
|
97 |
|
98 CCmdInput::~CCmdInput() |
|
99 { |
|
100 } |
|
101 |
|
102 CCmdInput::CCmdInput() |
|
103 { |
|
104 } |
|
105 |
|
106 void CCmdInput::ShowKeyMappings() |
|
107 { |
|
108 IoUtils::CTextBuffer* buf = IoUtils::CTextBuffer::NewLC(0x100); |
|
109 |
|
110 buf->AppendL(_L("Input key\tScan Code\tModifiers\tLabel\r\n")); |
|
111 for (TInt i = 0; i < KNumKeyMappings; ++i) |
|
112 { |
|
113 const TKeyMapping& mapping = KKeyMappings[i]; |
|
114 if (mapping.iConsoleKey == EKeyUpArrow) |
|
115 { |
|
116 buf->AppendFormatL(_L("Up (0x%x)\t0x%x\t0x%x\t%s\r\n"), mapping.iConsoleKey, mapping.iScanCode, mapping.iModifiers, mapping.iLabel); |
|
117 } |
|
118 else if (mapping.iConsoleKey == EKeyDownArrow) |
|
119 { |
|
120 buf->AppendFormatL(_L("Down (0x%x)\t0x%x\t0x%x\t%s\r\n"), mapping.iConsoleKey, mapping.iScanCode, mapping.iModifiers, mapping.iLabel); |
|
121 } |
|
122 else if (mapping.iConsoleKey == EKeyLeftArrow) |
|
123 { |
|
124 buf->AppendFormatL(_L("Left (0x%x)\t0x%x\t0x%x\t%s\r\n"), mapping.iConsoleKey, mapping.iScanCode, mapping.iModifiers, mapping.iLabel); |
|
125 } |
|
126 else if (mapping.iConsoleKey == EKeyRightArrow) |
|
127 { |
|
128 buf->AppendFormatL(_L("Right (0x%x)\t0x%x\t0x%x\t%s\r\n"), mapping.iConsoleKey, mapping.iScanCode, mapping.iModifiers, mapping.iLabel); |
|
129 } |
|
130 else if (mapping.iConsoleKey == EKeyEnter) |
|
131 { |
|
132 buf->AppendFormatL(_L("Enter (0x%x)\t0x%x\t0x%x\t%s\r\n"), mapping.iConsoleKey, mapping.iScanCode, mapping.iModifiers, mapping.iLabel); |
|
133 } |
|
134 else |
|
135 { |
|
136 buf->AppendFormatL(_L("%c (0x%x)\t0x%x\t0x%x\t%s\r\n"), mapping.iConsoleKey, mapping.iConsoleKey, mapping.iScanCode, mapping.iModifiers, mapping.iLabel); |
|
137 } |
|
138 } |
|
139 |
|
140 CTextFormatter* formatter = CTextFormatter::NewLC(Stdout()); |
|
141 formatter->TabulateL(0, 2, buf->Descriptor()); |
|
142 Write(formatter->Descriptor()); |
|
143 |
|
144 CleanupStack::PopAndDestroy(2, buf); |
|
145 } |
|
146 |
|
147 void CCmdInput::SimulateKeyL(TInt aConsoleKey) |
|
148 { |
|
149 for (TInt i = 0; i < KNumKeyMappings; ++i) |
|
150 { |
|
151 const TKeyMapping& mapping = KKeyMappings[i]; |
|
152 if (aConsoleKey == mapping.iConsoleKey) |
|
153 { |
|
154 LtkUtils::InjectRawKeyEvent(mapping.iScanCode, mapping.iModifiers, 0); |
|
155 break; |
|
156 } |
|
157 } |
|
158 } |
|
159 |
|
160 const TDesC& CCmdInput::Name() const |
|
161 { |
|
162 _LIT(KName, "input"); |
|
163 return KName; |
|
164 } |
|
165 |
|
166 void CCmdInput::ArgumentsL(RCommandArgumentList& aArguments) |
|
167 { |
|
168 aArguments.AppendUintL(iConsoleKey, _L("key")); |
|
169 } |
|
170 |
|
171 void CCmdInput::OptionsL(RCommandOptionList& aOptions) |
|
172 { |
|
173 aOptions.AppendBoolL(iShow, _L("show")); |
|
174 aOptions.AppendUintL(iScanCode, _L("scan-code")); |
|
175 aOptions.AppendUintL(iModifiers, _L("modifiers")); |
|
176 } |
|
177 |
|
178 void CCmdInput::DoRunL() |
|
179 { |
|
180 if (iShow) |
|
181 { |
|
182 ShowKeyMappings(); |
|
183 } |
|
184 else if (iOptions.IsPresent(&iScanCode)) |
|
185 { |
|
186 LtkUtils::InjectRawKeyEvent(iScanCode, iModifiers, 0); |
|
187 } |
|
188 else |
|
189 { |
|
190 if (iArguments.IsPresent(&iConsoleKey)) |
|
191 { |
|
192 SimulateKeyL(iConsoleKey); |
|
193 } |
|
194 else |
|
195 { |
|
196 RIoConsoleReadHandle& stdin = Stdin(); |
|
197 stdin.SetReadModeL(RIoReadHandle::EFull); |
|
198 TBuf<1> buf; |
|
199 TInt err = KErrNone; |
|
200 while (err == KErrNone) |
|
201 { |
|
202 err = stdin.Read(buf); |
|
203 if (err == KErrNone) |
|
204 { |
|
205 if (buf[0] == 'q') |
|
206 { |
|
207 break; |
|
208 } |
|
209 else |
|
210 { |
|
211 SimulateKeyL(buf[0]); |
|
212 } |
|
213 } |
|
214 } |
|
215 } |
|
216 } |
|
217 } |