2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2017 Kevin Lamonte
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
31 import jexer
.TKeypress
;
34 * This class encapsulates a keyboard input event.
36 public final class TKeypressEvent
extends TInputEvent
{
41 private TKeypress key
;
48 public TKeypress
getKey() {
55 * @param key the TKeypress received
57 public TKeypressEvent(final TKeypress key
) {
64 * @param isKey is true, this is a function key
65 * @param fnKey the function key code (only valid if isKey is true)
66 * @param ch the character (only valid if fnKey is false)
67 * @param alt if true, ALT was pressed with this keystroke
68 * @param ctrl if true, CTRL was pressed with this keystroke
69 * @param shift if true, SHIFT was pressed with this keystroke
71 public TKeypressEvent(final boolean isKey
, final int fnKey
, final char ch
,
72 final boolean alt
, final boolean ctrl
, final boolean shift
) {
74 this.key
= new TKeypress(isKey
, fnKey
, ch
, alt
, ctrl
, shift
);
80 * @param key the TKeypress received
81 * @param alt if true, ALT was pressed with this keystroke
82 * @param ctrl if true, CTRL was pressed with this keystroke
83 * @param shift if true, SHIFT was pressed with this keystroke
85 public TKeypressEvent(final TKeypress key
,
86 final boolean alt
, final boolean ctrl
, final boolean shift
) {
88 this.key
= new TKeypress(key
.isFnKey(), key
.getKeyCode(), key
.getChar(),
93 * Create a duplicate instance.
95 * @return duplicate intance
97 public TKeypressEvent
dup() {
98 TKeypressEvent keypress
= new TKeypressEvent(key
.dup());
103 * Comparison check. All fields must match to return true.
105 * @param rhs another TKeypressEvent or TKeypress instance
106 * @return true if all fields are equal
109 public boolean equals(final Object rhs
) {
110 if (!(rhs
instanceof TKeypressEvent
)
111 && !(rhs
instanceof TKeypress
)
116 if (rhs
instanceof TKeypressEvent
) {
117 TKeypressEvent that
= (TKeypressEvent
) rhs
;
118 return (key
.equals(that
.key
)
119 && (getTime().equals(that
.getTime())));
122 TKeypress that
= (TKeypress
) rhs
;
123 return (key
.equals(that
));
127 * Hashcode uses all fields in equals().
132 public int hashCode() {
136 hash
= (B
* hash
) + getTime().hashCode();
137 hash
= (B
* hash
) + key
.hashCode();
142 * Make human-readable description of this TKeypressEvent.
144 * @return displayable String
147 public String
toString() {
148 return String
.format("Keypress: %s", key
.toString());