2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2019 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 class TKeypressEvent
extends TInputEvent
{
38 // ------------------------------------------------------------------------
39 // Variables --------------------------------------------------------------
40 // ------------------------------------------------------------------------
45 private TKeypress key
;
47 // ------------------------------------------------------------------------
48 // Constructors -----------------------------------------------------------
49 // ------------------------------------------------------------------------
54 * @param key the TKeypress received
56 public TKeypressEvent(final TKeypress key
) {
63 * @param isKey is true, this is a function key
64 * @param fnKey the function key code (only valid if isKey is true)
65 * @param ch the character (only valid if fnKey is false)
66 * @param alt if true, ALT was pressed with this keystroke
67 * @param ctrl if true, CTRL was pressed with this keystroke
68 * @param shift if true, SHIFT was pressed with this keystroke
70 public TKeypressEvent(final boolean isKey
, final int fnKey
, final int ch
,
71 final boolean alt
, final boolean ctrl
, final boolean shift
) {
73 this.key
= new TKeypress(isKey
, fnKey
, ch
, alt
, ctrl
, shift
);
79 * @param key the TKeypress received
80 * @param alt if true, ALT was pressed with this keystroke
81 * @param ctrl if true, CTRL was pressed with this keystroke
82 * @param shift if true, SHIFT was pressed with this keystroke
84 public TKeypressEvent(final TKeypress key
,
85 final boolean alt
, final boolean ctrl
, final boolean shift
) {
87 this.key
= new TKeypress(key
.isFnKey(), key
.getKeyCode(), key
.getChar(),
91 // ------------------------------------------------------------------------
92 // TInputEvent ------------------------------------------------------------
93 // ------------------------------------------------------------------------
96 * Comparison check. All fields must match to return true.
98 * @param rhs another TKeypressEvent or TKeypress instance
99 * @return true if all fields are equal
102 public boolean equals(final Object rhs
) {
103 if (!(rhs
instanceof TKeypressEvent
)
104 && !(rhs
instanceof TKeypress
)
109 if (rhs
instanceof TKeypressEvent
) {
110 TKeypressEvent that
= (TKeypressEvent
) rhs
;
111 return (key
.equals(that
.key
)
112 && (getTime().equals(that
.getTime())));
115 TKeypress that
= (TKeypress
) rhs
;
116 return (key
.equals(that
));
120 * Hashcode uses all fields in equals().
125 public int hashCode() {
129 hash
= (B
* hash
) + getTime().hashCode();
130 hash
= (B
* hash
) + key
.hashCode();
135 * Make human-readable description of this TKeypressEvent.
137 * @return displayable String
140 public String
toString() {
141 return String
.format("Keypress: %s", key
.toString());
144 // ------------------------------------------------------------------------
145 // TKeypressEvent ---------------------------------------------------------
146 // ------------------------------------------------------------------------
153 public TKeypress
getKey() {
158 * Create a duplicate instance.
160 * @return duplicate intance
162 public TKeypressEvent
dup() {
163 TKeypressEvent keypress
= new TKeypressEvent(key
.dup());