author | alwin <alwin> | 2005-02-28 09:40:30 (UTC) |
---|---|---|
committer | alwin <alwin> | 2005-02-28 09:40:30 (UTC) |
commit | 2b64a84d39eeed5681d0ee5068c7d11a01527750 (patch) (unidiff) | |
tree | c8693340dbc5ef5e2f9afa90b690829ddff2c4bd /noncore/applets/keyhelper/keyhelperapplet/misc/KeyRepeater.cpp | |
parent | 61fa699140c5efbb6ba0bf2a62f7e8fbf62976be (diff) | |
download | opie-2b64a84d39eeed5681d0ee5068c7d11a01527750.zip opie-2b64a84d39eeed5681d0ee5068c7d11a01527750.tar.gz opie-2b64a84d39eeed5681d0ee5068c7d11a01527750.tar.bz2 |
other keymapping tool - not working this moment, I have to check it out
- the reason is that the config file is somewhat easier to understand than
from zkbapplet and has a nice config tool.
Please don't put it into any repositories this moment.
Diffstat (limited to 'noncore/applets/keyhelper/keyhelperapplet/misc/KeyRepeater.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/applets/keyhelper/keyhelperapplet/misc/KeyRepeater.cpp | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/noncore/applets/keyhelper/keyhelperapplet/misc/KeyRepeater.cpp b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyRepeater.cpp new file mode 100644 index 0000000..84a8a89 --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyRepeater.cpp | |||
@@ -0,0 +1,140 @@ | |||
1 | #include "KeyRepeater.h" | ||
2 | |||
3 | KeyRepeater::KeyRepeater() | ||
4 | { | ||
5 | qDebug("KeyRepeater::KeyRepeater()"); | ||
6 | m_pTimer = new QTimer(this); | ||
7 | connect(m_pTimer, SIGNAL(timeout()), this, SLOT(autoRepeat())); | ||
8 | init(); | ||
9 | } | ||
10 | |||
11 | KeyRepeater::~KeyRepeater() | ||
12 | { | ||
13 | qDebug("KeyRepeater::~KeyRepeater()"); | ||
14 | delete m_pTimer; | ||
15 | } | ||
16 | |||
17 | void KeyRepeater::start(int unicode, int keycode, int modifiers) | ||
18 | { | ||
19 | m_unicode = unicode; | ||
20 | m_keycode = keycode; | ||
21 | m_modifiers = modifiers; | ||
22 | if(m_mode == ENABLE){ | ||
23 | m_pTimer->stop(); | ||
24 | if(isRepeatable(keycode)){ | ||
25 | /* repeater start */ | ||
26 | m_pTimer->start(m_repeatdelay, TRUE); | ||
27 | } | ||
28 | } | ||
29 | } | ||
30 | |||
31 | void KeyRepeater::stop(int keycode) | ||
32 | { | ||
33 | if(keycode == 0 | ||
34 | || keycode == m_keycode | ||
35 | || isRepeatable(keycode) == false){ | ||
36 | m_pTimer->stop(); | ||
37 | } | ||
38 | } | ||
39 | |||
40 | void KeyRepeater::init() | ||
41 | { | ||
42 | m_mode = ENABLE; | ||
43 | m_repeatdelay = 400; | ||
44 | m_repeatperiod = 60; | ||
45 | m_disablekeys.append(0); | ||
46 | m_disablekeys.append(Qt::Key_Escape); | ||
47 | m_disablekeys.append(Qt::Key_Shift); | ||
48 | m_disablekeys.append(Qt::Key_Control); | ||
49 | m_disablekeys.append(Qt::Key_Alt); | ||
50 | m_disablekeys.append(Qt::Key_Meta); | ||
51 | for(int i=Qt::Key_F1; i<=Qt::Key_F35; i++){ | ||
52 | m_disablekeys.append(i); | ||
53 | } | ||
54 | } | ||
55 | |||
56 | void KeyRepeater::clear() | ||
57 | { | ||
58 | m_disablekeys.clear(); | ||
59 | } | ||
60 | |||
61 | void KeyRepeater::reset() | ||
62 | { | ||
63 | clear(); | ||
64 | init(); | ||
65 | } | ||
66 | |||
67 | void KeyRepeater::setRepeatable(int keycode, bool enable) | ||
68 | { | ||
69 | if(enable){ | ||
70 | QValueList<int>::Iterator it = m_disablekeys.find(keycode); | ||
71 | if(it != m_disablekeys.end()){ | ||
72 | m_disablekeys.remove(it); | ||
73 | } | ||
74 | } else { | ||
75 | if(m_disablekeys.contains(keycode) == false){ | ||
76 | m_disablekeys.append(keycode); | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | |||
81 | bool KeyRepeater::isRepeatable(int keycode) | ||
82 | { | ||
83 | if(m_disablekeys.contains(keycode)){ | ||
84 | return(false); | ||
85 | } else { | ||
86 | return(true); | ||
87 | } | ||
88 | } | ||
89 | |||
90 | void KeyRepeater::autoRepeat() | ||
91 | { | ||
92 | /* key release event */ | ||
93 | #if 0 | ||
94 | sendKeyEvent( | ||
95 | m_unicode, | ||
96 | m_keycode, | ||
97 | m_modifiers, | ||
98 | FALSE, | ||
99 | TRUE); | ||
100 | /* key press event */ | ||
101 | sendKeyEvent( | ||
102 | m_unicode, | ||
103 | m_keycode, | ||
104 | m_modifiers, | ||
105 | TRUE, | ||
106 | TRUE); | ||
107 | #else | ||
108 | emit keyEvent( | ||
109 | m_unicode, | ||
110 | m_keycode, | ||
111 | m_modifiers, | ||
112 | FALSE, | ||
113 | TRUE); | ||
114 | /* key press event */ | ||
115 | emit keyEvent( | ||
116 | m_unicode, | ||
117 | m_keycode, | ||
118 | m_modifiers, | ||
119 | TRUE, | ||
120 | TRUE); | ||
121 | #endif | ||
122 | /* start auto repeat */ | ||
123 | m_pTimer->start(m_repeatperiod); | ||
124 | #if 0 | ||
125 | qDebug("autoRepeat[%x][%x][%x]", | ||
126 | m_unicode, | ||
127 | m_keycode, | ||
128 | m_modifiers); | ||
129 | #endif | ||
130 | } | ||
131 | |||
132 | void KeyRepeater::statistics() | ||
133 | { | ||
134 | qWarning("KeyRepeater::statistics()"); | ||
135 | qWarning(" delay[%d] period[%d]", m_repeatdelay, m_repeatperiod); | ||
136 | for(QValueList<int>::Iterator it=m_disablekeys.begin(); | ||
137 | it!=m_disablekeys.end(); ++it){ | ||
138 | qDebug(" disable[%x]", *it); | ||
139 | } | ||
140 | } | ||