1 #include <QSymbianEvent> |
|
2 #include <QFile> |
|
3 #include <QTextStream> |
|
4 #include <QDebug> |
|
5 |
|
6 #include <W32STD.H> |
|
7 #include <eikenv.h> |
|
8 |
|
9 #include "keycapturingapplication.h" |
|
10 |
|
11 /*! |
|
12 |
|
13 */ |
|
14 void writeDebug(const QString &message) |
|
15 { |
|
16 QFile file("c:/keycapturingapplication.log"); |
|
17 if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) { |
|
18 qDebug() << "DialogLauncherView::writeDebug - file open failed"; |
|
19 return; |
|
20 } |
|
21 |
|
22 QTextStream out(&file); |
|
23 out << message << "\n"; |
|
24 |
|
25 file.close(); |
|
26 } |
|
27 |
|
28 /*! |
|
29 |
|
30 */ |
|
31 KeyCapturingApplication::KeyCapturingApplication(int &argc, char *argv[], int keyCode) : |
|
32 HbApplication(argc, argv), mKeyCode(keyCode), mKeyCaptureHandle(-1) |
|
33 { |
|
34 CEikonEnv *env = CEikonEnv::Static(); |
|
35 mKeyCaptureHandle = env->RootWin().CaptureKey(keyCode, 0, 0); |
|
36 } |
|
37 |
|
38 /*! |
|
39 |
|
40 */ |
|
41 KeyCapturingApplication::~KeyCapturingApplication() |
|
42 { |
|
43 CEikonEnv *env = CEikonEnv::Static(); |
|
44 env->RootWin().CancelCaptureKey(mKeyCaptureHandle); |
|
45 } |
|
46 |
|
47 bool KeyCapturingApplication::symbianEventFilter(const QSymbianEvent *event) |
|
48 { |
|
49 if (event->type() == QSymbianEvent::WindowServerEvent) { |
|
50 const TWsEvent* wsEvent = event->windowServerEvent(); |
|
51 if (wsEvent->Type() == EEventKey) { |
|
52 writeDebug(QString("Key Event:")); |
|
53 writeDebug(QString("\tkey code: %1").arg(wsEvent->Key()->iCode)); |
|
54 writeDebug(QString("\tscan code: %1").arg(wsEvent->Key()->iScanCode)); |
|
55 if (wsEvent->Key()->iCode == mKeyCode) |
|
56 { |
|
57 emit capturedKeyEvent(); |
|
58 } |
|
59 } |
|
60 } |
|
61 return HbApplication::symbianEventFilter(event); |
|
62 } |
|