1 /*
2 * Copyright (c) 2007, 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 */
105 typeKey(KeyEvent.VK_A);
106 typeKey(KeyEvent.VK_B);
107 typeKey(KeyEvent.VK_SPACE);
108 typeKey(KeyEvent.VK_Z);
109 }
110
111 private static void typeKey(int keyChar){
112 try {
113 robot.keyPress(keyChar);
114 robot.delay(5);
115 } finally {
116 robot.keyRelease(keyChar);
117 }
118 robot.delay(100);
119 }
120
121 private void traceKey(String k, KeyEvent e){
122 long eventTime = e.getWhen();
123 long currTime = System.currentTimeMillis();
124 long diff = currTime - eventTime;
125 Sysout.println(k + " diff is " + diff + ", event is "+ e);
126 if (diff < 0 ||
127 diff > REASONABLE_PATH_TIME)
128 {
129 AbstractTest.fail(k + " diff is " + diff + ", event = "+e);
130 }
131 }
132
133 public void keyTyped(KeyEvent e){
134 traceKey("keytyped",e);
135 }
136 public void keyPressed(KeyEvent e){
137 traceKey("keypress",e);
138 }
139 public void keyReleased(KeyEvent e){
140 traceKey("keyrelease",e);
141 }
142 }
|
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 */
105 typeKey(KeyEvent.VK_A);
106 typeKey(KeyEvent.VK_B);
107 typeKey(KeyEvent.VK_SPACE);
108 typeKey(KeyEvent.VK_Z);
109 }
110
111 private static void typeKey(int keyChar){
112 try {
113 robot.keyPress(keyChar);
114 robot.delay(5);
115 } finally {
116 robot.keyRelease(keyChar);
117 }
118 robot.delay(100);
119 }
120
121 private void traceKey(String k, KeyEvent e){
122 long eventTime = e.getWhen();
123 long currTime = System.currentTimeMillis();
124 long diff = currTime - eventTime;
125 System.out.println(k + " diff is " + diff + ", event is "+ e);
126 if (diff < 0 ||
127 diff > REASONABLE_PATH_TIME)
128 {
129 AbstractTest.fail(k + " diff is " + diff + ", event = "+e);
130 }
131 }
132
133 public void keyTyped(KeyEvent e){
134 traceKey("keytyped",e);
135 }
136 public void keyPressed(KeyEvent e){
137 traceKey("keypress",e);
138 }
139 public void keyReleased(KeyEvent e){
140 traceKey("keyrelease",e);
141 }
142 }
|