-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
80 lines (63 loc) · 2.09 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
@file main.cpp
@brief main app
@author Faizal Zakaria
@date 2012-07-20
*/
#include <QtGui>
#include "mainwindow.h"
#include "key_filter.h"
#if defined RMPLATFORM
#include <QWSServer>
#endif
bool remappingKeyCallback( int keycode, void* ctx );
bool exitApplication( int keycode, void* ctx );
int main(int argc, char *argv[])
{
QApplication a(argc, argv, QApplication::GuiServer );
KeyFilter* pFilter = new KeyFilter();
MainWindow mainWindow;
mainWindow.show();
QWSServer::addKeyboardFilter( pFilter );
QWSServer::setCursorVisible( false );
pFilter->addKeyCallback( Qt::Key_MediaNext, remappingKeyCallback, NULL );
pFilter->addKeyCallback( Qt::Key_MediaPrevious, remappingKeyCallback, NULL );
pFilter->addKeyCallback( Qt::Key_Return, remappingKeyCallback, NULL );
pFilter->addKeyCallback( Qt::Key_Home, exitApplication, NULL );
return a.exec();
}
bool remappingKeyCallback( int keycode, void* ctx )
{
QKeyEvent* ev;
ctx = ctx;
switch( keycode )
{
case Qt::Key_MediaPrevious:
printf( "Remapping to backtab\n" );
ev = new QKeyEvent( QEvent::KeyPress, Qt::Key_Backtab, 0 );
QCoreApplication::sendEvent( (QObject*)QApplication::focusWidget(), ev );
ev = new QKeyEvent( QEvent::KeyRelease, Qt::Key_Tab, 0 );
QCoreApplication::sendEvent( (QObject*)QApplication::focusWidget(), ev );
break;
case Qt::Key_MediaNext:
printf( "Remapping to tab\n" );
ev = new QKeyEvent( QEvent::KeyPress, Qt::Key_Tab, 0 );
QCoreApplication::sendEvent( (QObject*)QApplication::focusWidget(), ev );
ev = new QKeyEvent( QEvent::KeyRelease, Qt::Key_Tab, 0 );
QCoreApplication::sendEvent( (QObject*)QApplication::focusWidget(), ev );
break;
case Qt::Key_Return:
printf( "Remapping to select\n" );
ev = new QKeyEvent( QEvent::KeyPress, Qt::Key_Select, 0 );
QCoreApplication::sendEvent( (QObject*)QApplication::focusWidget() , ev );
ev = new QKeyEvent( QEvent::KeyRelease, Qt::Key_Select, 0 );
QCoreApplication::sendEvent( (QObject*)QApplication::focusWidget(), ev );
break;
}
return true;
}
bool exitApplication( int keycode, void* ctx )
{
QApplication::exit(0);
return true;
}