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/KeyAction.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/KeyAction.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/applets/keyhelper/keyhelperapplet/misc/KeyAction.cpp | 253 |
1 files changed, 253 insertions, 0 deletions
diff --git a/noncore/applets/keyhelper/keyhelperapplet/misc/KeyAction.cpp b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyAction.cpp new file mode 100644 index 0000000..f44138c --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/misc/KeyAction.cpp | |||
@@ -0,0 +1,253 @@ | |||
1 | #include "KeyAction.h" | ||
2 | |||
3 | KeyAction::KeyAction() | ||
4 | { | ||
5 | qDebug("KeyAction::KeyAction()"); | ||
6 | enable(); | ||
7 | } | ||
8 | |||
9 | KeyAction::~KeyAction() | ||
10 | { | ||
11 | qDebug("KeyAction::~KeyAction()"); | ||
12 | } | ||
13 | |||
14 | void KeyAction::init() | ||
15 | { | ||
16 | ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); | ||
17 | |||
18 | QString oldgroup = cfg.getGroup(); | ||
19 | cfg.setGroup("Global"); | ||
20 | |||
21 | m_keepToggle = cfg.readBoolEntry("KeepToggle", true); | ||
22 | |||
23 | m_excludeKeys.clear(); | ||
24 | if(cfg.hasKey("ExcludeKeys")){ | ||
25 | QStringList keys = cfg.readListEntry("ExcludeKeys", ','); | ||
26 | for(QStringList::Iterator it=keys.begin(); | ||
27 | it!=keys.end(); ++it){ | ||
28 | int code; | ||
29 | if((*it).find("0x") == 0){ | ||
30 | code = KHUtil::hex2int(*it); | ||
31 | } else { | ||
32 | code = KeyNames::getCode(*it); | ||
33 | } | ||
34 | if(code > 0){ | ||
35 | m_excludeKeys.append(code); | ||
36 | } | ||
37 | } | ||
38 | } else { | ||
39 | m_excludeKeys.append(Qt::Key_F34); | ||
40 | } | ||
41 | |||
42 | m_presscnt = 0; | ||
43 | m_check = true; | ||
44 | m_keep_toggle_code = 0; | ||
45 | m_capture = false; | ||
46 | cfg.setGroup(oldgroup); | ||
47 | } | ||
48 | |||
49 | void KeyAction::setAction(int unicode, int keycode, int modifiers, | ||
50 | bool isPress, bool autoRepeat) | ||
51 | { | ||
52 | m_unicode = unicode; | ||
53 | m_keycode = keycode; | ||
54 | m_modifiers = modifiers; | ||
55 | m_isPress = isPress; | ||
56 | m_autoRepeat = autoRepeat; | ||
57 | } | ||
58 | |||
59 | bool KeyAction::checkState() | ||
60 | { | ||
61 | if(0 < m_unicode && m_unicode < 0xFFFF){ | ||
62 | QChar ch(m_unicode); | ||
63 | QChar::Category category = ch.category(); | ||
64 | if(category == QChar::Letter_Lowercase){ | ||
65 | if(m_modifiers == 0){ | ||
66 | m_pMappings->setCapsLock(false); | ||
67 | return(true); | ||
68 | } else if(m_modifiers == Qt::ShiftButton){ | ||
69 | m_pMappings->setCapsLock(true); | ||
70 | return(true); | ||
71 | } | ||
72 | } else if(category == QChar::Letter_Uppercase){ | ||
73 | if(m_modifiers == 0){ | ||
74 | m_pMappings->setCapsLock(true); | ||
75 | return(true); | ||
76 | } else if(m_modifiers == Qt::ShiftButton){ | ||
77 | m_pMappings->setCapsLock(false); | ||
78 | return(true); | ||
79 | } | ||
80 | } | ||
81 | } | ||
82 | return(false); | ||
83 | } | ||
84 | |||
85 | void KeyAction::sendKeyEvent(int unicode, int keycode, int modifiers, | ||
86 | bool isPress, bool autoRepeat) | ||
87 | { | ||
88 | if(m_hookChannel.isEmpty()){ | ||
89 | QWSServer::sendKeyEvent(unicode, keycode, modifiers, isPress, autoRepeat); | ||
90 | } else { | ||
91 | if(QCopChannel::isRegistered(m_hookChannel)){ | ||
92 | QCopEnvelope e(m_hookChannel, "keyEvent(int,int,int,int,int)"); | ||
93 | e << unicode << keycode << modifiers << (int)isPress << (int)autoRepeat; | ||
94 | } else { | ||
95 | m_hookChannel = ""; | ||
96 | QWSServer::sendKeyEvent(unicode, keycode, modifiers, isPress, autoRepeat); | ||
97 | } | ||
98 | } | ||
99 | } | ||
100 | |||
101 | bool KeyAction::doAction() | ||
102 | { | ||
103 | if(m_enable == false){ | ||
104 | return(false); | ||
105 | } | ||
106 | #if 0 | ||
107 | if(m_excludeKeys.contains(m_keycode)){ | ||
108 | return(false); | ||
109 | } | ||
110 | #endif | ||
111 | if(!m_autoRepeat){ | ||
112 | qDebug("recv[%x][%x][%x][%d]", | ||
113 | m_unicode, | ||
114 | m_keycode, | ||
115 | m_modifiers, | ||
116 | m_isPress); | ||
117 | } | ||
118 | |||
119 | if(m_autoRepeat && !m_excludeKeys.contains(m_keycode)){ | ||
120 | KeyRepeater::RepeaterMode repMode = m_pRepeater->getMode(); | ||
121 | if(repMode == KeyRepeater::ENABLE | ||
122 | || repMode == KeyRepeater::KILL){ | ||
123 | /* autoRepeat ¤Ï̵»ë */ | ||
124 | return(true); | ||
125 | } | ||
126 | } | ||
127 | |||
128 | if(m_pRepeater->isRepeatable(m_keycode)){ | ||
129 | if(m_isPress){ | ||
130 | m_presscnt++; | ||
131 | } else { | ||
132 | m_presscnt--; | ||
133 | if(m_presscnt <= 0){ | ||
134 | m_pRepeater->stop(); | ||
135 | m_presscnt = 0; | ||
136 | } | ||
137 | } | ||
138 | } | ||
139 | |||
140 | if(m_check && m_isPress){ | ||
141 | /* check capslock state */ | ||
142 | if(checkState()){ | ||
143 | m_check = false; | ||
144 | } | ||
145 | } | ||
146 | |||
147 | int unicode, keycode, modifiers; | ||
148 | /* keep toggle reset */ | ||
149 | if(m_keepToggle && m_keep_toggle_code != 0){ | ||
150 | if(m_keep_toggle_code != m_keycode){ | ||
151 | m_pModifiers->resetToggles(); | ||
152 | m_keep_toggle_code = 0; | ||
153 | } else { | ||
154 | m_pModifiers->keepToggles(); | ||
155 | } | ||
156 | } | ||
157 | |||
158 | /* modifier ¾õÂÖ¼èÆÀ */ | ||
159 | int keymask = m_pModifiers->getState(m_modifiers); | ||
160 | modifiers = m_pModifiers->getModifiers(m_modifiers); | ||
161 | |||
162 | bool isModMapped = false; | ||
163 | /* modifier ¾õÂÖ¹¹¿· */ | ||
164 | if(m_autoRepeat == false){ | ||
165 | if(m_isPress){ | ||
166 | isModMapped = m_pModifiers->pressKey(m_keycode, m_modifiers); | ||
167 | } else { | ||
168 | m_pModifiers->releaseKey(m_keycode); | ||
169 | } | ||
170 | } | ||
171 | |||
172 | if(m_capture && m_isPress && m_autoRepeat == false){ | ||
173 | QCopEnvelope e("QPE/KeyHelperConf", "event(int,int,int)"); | ||
174 | e << m_keycode << m_unicode << modifiers; | ||
175 | } | ||
176 | |||
177 | /* keyextension ŬÍÑ */ | ||
178 | bool fKeyCancel = m_pExtensions->doKey(m_keycode, keymask, m_isPress); | ||
179 | if(fKeyCancel){ | ||
180 | if(m_keepToggle){ | ||
181 | m_keep_toggle_code = m_keycode; | ||
182 | } else { | ||
183 | m_pModifiers->resetToggles(); | ||
184 | } | ||
185 | m_pRepeater->stop(); | ||
186 | return(true); | ||
187 | } | ||
188 | |||
189 | /* keymapping ŬÍÑ */ | ||
190 | #if 0 | ||
191 | bool isMapped = m_pMappings->apply(m_keycode, keymask, m_isPress); | ||
192 | if(isMapped == false){ | ||
193 | if(m_pMappings->isDefined()){ | ||
194 | m_pMappings->setOriginal(m_unicode, m_modifiers); | ||
195 | } else { | ||
196 | m_pMappings->setUnicode(m_unicode); | ||
197 | //m_pMappings->setKeycode(m_keycode); | ||
198 | } | ||
199 | //return(false); | ||
200 | } | ||
201 | #else | ||
202 | bool isMapped = m_pMappings->apply(m_unicode, m_keycode, m_modifiers, | ||
203 | keymask, m_isPress); | ||
204 | #endif | ||
205 | |||
206 | /* modifier ŬÍÑ */ | ||
207 | m_pMappings->setModifiers(modifiers); | ||
208 | |||
209 | keycode = m_pMappings->getKeycode(); | ||
210 | if(keycode <= 0){ | ||
211 | return(true); | ||
212 | } | ||
213 | |||
214 | if(/*m_autoRepeat == false &&*/ m_isPress){ | ||
215 | if(isModMapped == false || (isModMapped && isMapped)){ | ||
216 | if(m_pModifiers->isModifier(keycode) == false){ | ||
217 | m_pModifiers->resetToggles(); | ||
218 | } | ||
219 | } | ||
220 | } | ||
221 | unicode = m_pMappings->getUnicode(); | ||
222 | modifiers = m_pMappings->getModifiers(); | ||
223 | if(keycode > 0){ | ||
224 | /* disable mapping */ | ||
225 | if(m_excludeKeys.contains(keycode)){ | ||
226 | return(false); | ||
227 | } | ||
228 | /* send key event */ | ||
229 | sendKeyEvent( | ||
230 | unicode, | ||
231 | keycode, | ||
232 | modifiers, | ||
233 | m_isPress, | ||
234 | m_autoRepeat); | ||
235 | } | ||
236 | if(m_isPress){ | ||
237 | /* repeater start */ | ||
238 | m_pRepeater->start(unicode, keycode, modifiers); | ||
239 | #if 0 | ||
240 | } else if(m_presscnt <= 0){ | ||
241 | m_presscnt = 0; | ||
242 | m_pRepeater->stop(); | ||
243 | #endif | ||
244 | } else { | ||
245 | m_pRepeater->stop(keycode); | ||
246 | } | ||
247 | qWarning("send[%x][%x][%x][%d]", | ||
248 | m_pMappings->getUnicode(), | ||
249 | m_pMappings->getKeycode(), | ||
250 | m_pMappings->getModifiers(), | ||
251 | m_isPress); | ||
252 | return(true); | ||
253 | } | ||