2 * Jexer - Java Text User Interface
4 * License: LGPLv3 or later
6 * This module is licensed under the GNU Lesser General Public License
7 * Version 3. Please see the file "COPYING" in this directory for more
8 * information about the GNU Lesser General Public License Version 3.
10 * Copyright (C) 2015 Kevin Lamonte
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this program; if not, see
24 * http://www.gnu.org/licenses/, or write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
33 import jexer
.TKeypress
;
36 * This class encapsulates a keyboard input event.
38 public final class TKeypressEvent
extends TInputEvent
{
43 private TKeypress key
;
50 public TKeypress
getKey() {
57 * @param key the TKeypress received
59 public TKeypressEvent(final TKeypress key
) {
66 * @param isKey is true, this is a function key
67 * @param fnKey the function key code (only valid if isKey is true)
68 * @param ch the character (only valid if fnKey is false)
69 * @param alt if true, ALT was pressed with this keystroke
70 * @param ctrl if true, CTRL was pressed with this keystroke
71 * @param shift if true, SHIFT was pressed with this keystroke
73 public TKeypressEvent(final boolean isKey
, final int fnKey
, final char ch
,
74 final boolean alt
, final boolean ctrl
, final boolean shift
) {
76 this.key
= new TKeypress(isKey
, fnKey
, ch
, alt
, ctrl
, shift
);
82 * @param key the TKeypress received
83 * @param alt if true, ALT was pressed with this keystroke
84 * @param ctrl if true, CTRL was pressed with this keystroke
85 * @param shift if true, SHIFT was pressed with this keystroke
87 public TKeypressEvent(final TKeypress key
,
88 final boolean alt
, final boolean ctrl
, final boolean shift
) {
90 this.key
= new TKeypress(key
.getIsKey(), key
.getFnKey(), key
.getCh(),
95 * Comparison check. All fields must match to return true.
97 * @param rhs another TKeypressEvent or TKeypress instance
98 * @return true if all fields are equal
101 public boolean equals(final Object rhs
) {
102 if (!(rhs
instanceof TKeypressEvent
)
103 && !(rhs
instanceof TKeypress
)
108 if (rhs
instanceof TKeypressEvent
) {
109 TKeypressEvent that
= (TKeypressEvent
) rhs
;
110 return (key
.equals(that
.key
)
111 && (getTime().equals(that
.getTime())));
114 TKeypress that
= (TKeypress
) rhs
;
115 return (key
.equals(that
));
119 * Hashcode uses all fields in equals().
124 public int hashCode() {
128 hash
= (B
* hash
) + getTime().hashCode();
129 hash
= (B
* hash
) + key
.hashCode();
134 * Make human-readable description of this TKeypressEvent.
136 * @return displayable String
139 public String
toString() {
140 return String
.format("Keypress: %s", key
.toString());