142 {
143
144
145
146
147
148
149
150
151
152 final boolean[] nowStates = new boolean[goal.keys.length];
153 final Boolean[] preEventStates = new Boolean[goal.keys.length];
154 boolean postEventAnyPressed = false;
155
156
157 for (int keyIdx = 0; keyIdx < goal.keys.length; keyIdx += 1) {
158 final KeyboardMap.KeyPair
key = goal.keys[keyIdx];
159 nowStates[keyIdx] = pressingRecords.containsKey(
key.physicalKey);
160 if (
key.logicalKey == eventLogicalKey) {
161 switch (getEventType(
event)) {
163 preEventStates[keyIdx] = false;
164 postEventAnyPressed = true;
165 if (!truePressed) {
166 postSynchronize.add(
167 () ->
168 synthesizeEvent(
169 false,
key.logicalKey, eventPhysicalKey,
event.getEventTime()));
170 }
171 break;
173
174
175
176 preEventStates[keyIdx] = nowStates[keyIdx];
177 break;
179
180
181
182 if (!truePressed) {
183 postSynchronize.add(
184 () ->
185 synthesizeEvent(
186 false,
key.logicalKey,
key.physicalKey,
event.getEventTime()));
187 }
188 preEventStates[keyIdx] = nowStates[keyIdx];
189 postEventAnyPressed = true;
190 break;
191 }
192 } else {
193 postEventAnyPressed = postEventAnyPressed || nowStates[keyIdx];
194 }
195 }
196
197
198 if (truePressed) {
199
200 for (int keyIdx = 0; keyIdx < goal.keys.length; keyIdx += 1) {
201 if (preEventStates[keyIdx] != null) {
202 continue;
203 }
204 if (postEventAnyPressed) {
205 preEventStates[keyIdx] = nowStates[keyIdx];
206 } else {
207 preEventStates[keyIdx] = true;
208 postEventAnyPressed = true;
209 }
210 }
211 if (!postEventAnyPressed) {
212 preEventStates[0] = true;
213 }
214 } else {
215 for (int keyIdx = 0; keyIdx < goal.keys.length; keyIdx += 1) {
216 if (preEventStates[keyIdx] != null) {
217 continue;
218 }
219 preEventStates[keyIdx] = false;
220 }
221 }
222
223
224 for (int keyIdx = 0; keyIdx < goal.keys.length; keyIdx += 1) {
225 if (nowStates[keyIdx] != preEventStates[keyIdx]) {
226 final KeyboardMap.KeyPair
key = goal.keys[keyIdx];
227 synthesizeEvent(
228 preEventStates[keyIdx],
key.logicalKey,
key.physicalKey,
event.getEventTime());
229 }
230 }
231 }