|
| 1 | +/* |
| 2 | + * Copyright (c) 1999, 2025, 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 | + */ |
| 23 | + |
| 24 | +/* |
| 25 | + * @test |
| 26 | + * bug 4268912 4115514 |
| 27 | + * summary Ensures that KeyEvent has right results for the following |
| 28 | + * non-numpad keys: Home/Eng/PageUp/PageDn |
| 29 | + * @library /java/awt/regtesthelpers |
| 30 | + * @build PassFailJFrame |
| 31 | + * @run main/manual HomeEndKeyTest |
| 32 | + */ |
| 33 | + |
| 34 | +import java.awt.BorderLayout; |
| 35 | +import java.awt.Frame; |
| 36 | +import java.awt.TextField; |
| 37 | +import java.awt.event.KeyEvent; |
| 38 | +import java.awt.event.KeyListener; |
| 39 | +import java.lang.reflect.InvocationTargetException; |
| 40 | + |
| 41 | + |
| 42 | +public class HomeEndKeyTest extends Frame implements KeyListener { |
| 43 | + static String INSTRUCTIONS = """ |
| 44 | + Before starting this test make sure that system shortcuts and |
| 45 | + keybindings for the keys in the list below are disabled. |
| 46 | + For example pressing "Print Screen" key should not launch |
| 47 | + screen capturing software. |
| 48 | + Click on the text field in the window named "Check keyCode values" |
| 49 | + and one by one start typing the keys in the list below. |
| 50 | + (If you do not have some of the keys on your keyboard skip it |
| 51 | + and move to the next line). |
| 52 | + After clicking each key look at the log area - the printed name |
| 53 | + and key code should correspond to the ones for the key you typed. |
| 54 | + Note that on some systems the graphical symbol for the key |
| 55 | + can be printed instead of the symbolic name. |
| 56 | + If you do not encounter unexpected key codes for the keys you typed, |
| 57 | + press "Pass". Otherwise press "Fail". |
| 58 | +
|
| 59 | + Key Keycode |
| 60 | + ------------------------- |
| 61 | + PrintScreen 154 |
| 62 | + ScrollLock 145 |
| 63 | + Pause 19 |
| 64 | +
|
| 65 | + Insert 155 |
| 66 | + Del 127 |
| 67 | + Home 36 |
| 68 | + End 35 |
| 69 | + PageUp 33 |
| 70 | + PageDown 34 |
| 71 | +
|
| 72 | + Left Arrow 37 |
| 73 | + Up Arrow 38 |
| 74 | + Right Arrow 39 |
| 75 | + Down Arrow 40 |
| 76 | + """; |
| 77 | + |
| 78 | + public HomeEndKeyTest() { |
| 79 | + super("Check KeyCode values"); |
| 80 | + setLayout(new BorderLayout()); |
| 81 | + TextField tf = new TextField(30); |
| 82 | + tf.addKeyListener(this); |
| 83 | + add(tf, BorderLayout.CENTER); |
| 84 | + pack(); |
| 85 | + } |
| 86 | + |
| 87 | + public void keyPressed(KeyEvent evt) { |
| 88 | + printKey(evt); |
| 89 | + } |
| 90 | + |
| 91 | + public void keyTyped(KeyEvent ignore) { |
| 92 | + } |
| 93 | + |
| 94 | + public void keyReleased(KeyEvent evt) { |
| 95 | + printKey(evt); |
| 96 | + } |
| 97 | + |
| 98 | + protected void printKey(KeyEvent evt) { |
| 99 | + String str; |
| 100 | + switch (evt.getID()) { |
| 101 | + case KeyEvent.KEY_PRESSED: |
| 102 | + str = "KEY_PRESSED"; |
| 103 | + break; |
| 104 | + case KeyEvent.KEY_RELEASED: |
| 105 | + str = "KEY_RELEASED"; |
| 106 | + break; |
| 107 | + default: |
| 108 | + str = "unknown type"; |
| 109 | + } |
| 110 | + |
| 111 | + str = str + ":name=" + KeyEvent.getKeyText(evt.getKeyCode()) + |
| 112 | + " keyCode=" + evt.getKeyCode(); |
| 113 | + PassFailJFrame.log(str); |
| 114 | + } |
| 115 | + |
| 116 | + public static void main(String[] args) throws InterruptedException, |
| 117 | + InvocationTargetException { |
| 118 | + PassFailJFrame.builder() |
| 119 | + .title("HomeEndKeyTest Instructions") |
| 120 | + .instructions(INSTRUCTIONS) |
| 121 | + .logArea(20) |
| 122 | + .testUI(HomeEndKeyTest::new) |
| 123 | + .build() |
| 124 | + .awaitAndCheck(); |
| 125 | + } |
| 126 | +} |
0 commit comments