1 /*
2 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
71 public ModifierRobotKeyTest() throws Exception {
72 modifierKeys = new int[4];
73 modifierKeys[0] = KeyEvent.VK_SHIFT;
74 modifierKeys[1] = KeyEvent.VK_CONTROL;
75 modifierKeys[2] = KeyEvent.VK_ALT;
76 modifierKeys[3] = KeyEvent.VK_ALT_GRAPH;
77
78 inputMasks = new int[4];
79 inputMasks[0] = InputEvent.SHIFT_MASK;
80 inputMasks[1] = InputEvent.CTRL_MASK;
81 inputMasks[2] = InputEvent.ALT_MASK;
82 inputMasks[3] = InputEvent.ALT_GRAPH_MASK;
83
84 modifierStatus = new boolean[modifierKeys.length];
85
86 textKeys = new int[2];
87 textKeys[0] = KeyEvent.VK_A;
88
89 String os = System.getProperty("os.name").toLowerCase();
90
91 if (os.contains("solaris") || os.contains("sunos"))
92 textKeys[1] = KeyEvent.VK_S;
93 else if (os.contains("os x"))
94 textKeys[1] = KeyEvent.VK_K;
95 else
96 textKeys[1] = KeyEvent.VK_I;
97
98 textStatus = new boolean[textKeys.length];
99
100 EventQueue.invokeAndWait( () -> { initializeGUI(); });
101 }
102
103 public void keyPressed(KeyEvent event) {
104 synchronized (lock) {
105 tempPress = true;
106 lock.notifyAll();
107
108 if (! startTest) {
109 return;
110 }
111 for (int x = 0; x < inputMasks.length; x++) {
112 if ((event.getModifiers() & inputMasks[x]) != 0) {
113 System.out.println("Modifier set: " +
|
1 /*
2 * Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
71 public ModifierRobotKeyTest() throws Exception {
72 modifierKeys = new int[4];
73 modifierKeys[0] = KeyEvent.VK_SHIFT;
74 modifierKeys[1] = KeyEvent.VK_CONTROL;
75 modifierKeys[2] = KeyEvent.VK_ALT;
76 modifierKeys[3] = KeyEvent.VK_ALT_GRAPH;
77
78 inputMasks = new int[4];
79 inputMasks[0] = InputEvent.SHIFT_MASK;
80 inputMasks[1] = InputEvent.CTRL_MASK;
81 inputMasks[2] = InputEvent.ALT_MASK;
82 inputMasks[3] = InputEvent.ALT_GRAPH_MASK;
83
84 modifierStatus = new boolean[modifierKeys.length];
85
86 textKeys = new int[2];
87 textKeys[0] = KeyEvent.VK_A;
88
89 String os = System.getProperty("os.name").toLowerCase();
90
91 if (os.contains("os x"))
92 textKeys[1] = KeyEvent.VK_K;
93 else
94 textKeys[1] = KeyEvent.VK_I;
95
96 textStatus = new boolean[textKeys.length];
97
98 EventQueue.invokeAndWait( () -> { initializeGUI(); });
99 }
100
101 public void keyPressed(KeyEvent event) {
102 synchronized (lock) {
103 tempPress = true;
104 lock.notifyAll();
105
106 if (! startTest) {
107 return;
108 }
109 for (int x = 0; x < inputMasks.length; x++) {
110 if ((event.getModifiers() & inputMasks[x]) != 0) {
111 System.out.println("Modifier set: " +
|