]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.eclipse.swt.win32.win32.x86_64/src/org/eclipse/swt/events/KeyEvent.java
Remove invalid SHA-256-Digests
[simantics/platform.git] / bundles / org.eclipse.swt.win32.win32.x86_64 / src / org / eclipse / swt / events / KeyEvent.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2011 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.swt.events;
15
16
17 import org.eclipse.swt.widgets.Event;
18
19 /**
20  * Instances of this class are sent as a result of
21  * keys being pressed and released on the keyboard.
22  * <p>
23  * When a key listener is added to a control, the control
24  * will take part in widget traversal.  By default, all
25  * traversal keys (such as the tab key and so on) are
26  * delivered to the control.  In order for a control to take
27  * part in traversal, it should listen for traversal events.
28  * Otherwise, the user can traverse into a control but not
29  * out.  Note that native controls such as table and tree
30  * implement key traversal in the operating system.  It is
31  * not necessary to add traversal listeners for these controls,
32  * unless you want to override the default traversal.
33  * </p>
34  *
35  * @see KeyListener
36  * @see TraverseListener
37  * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
38  */
39
40 public class KeyEvent extends TypedEvent {
41
42         /**
43          * the character represented by the key that was typed.
44          * This is the final character that results after all modifiers have been
45          * applied.  For example, when the user types Ctrl+A, the character value
46          * is 0x01.  It is important that applications do not attempt to modify the
47          * character value based on a stateMask (such as SWT.CTRL) or the resulting
48          * character will not be correct.
49          */
50         public char character;
51
52         /**
53          * the key code of the key that was typed,
54          * as defined by the key code constants in class <code>SWT</code>.
55          * When the character field of the event is ambiguous, this field
56          * contains the unicode value of the original character.  For example,
57          * typing Ctrl+M or Return both result in the character '\r' but the
58          * keyCode field will also contain '\r' when Return was typed.
59          *
60          * @see org.eclipse.swt.SWT
61          */
62         public int keyCode;
63
64         /**
65          * depending on the event, the location of key specified by the
66          * keyCode or character. The possible values for this field are
67          * <code>SWT.LEFT</code>, <code>SWT.RIGHT</code>, <code>SWT.KEYPAD</code>,
68          * or <code>SWT.NONE</code> representing the main keyboard area.
69          * <p>
70          * The location field can be used to differentiate key events that have
71          * the same key code and character but are generated by different keys
72          * on the keyboard. For example, a key down event with the key code equal
73          * to SWT.SHIFT can be generated by the left and the right shift keys on
74          * the keyboard.
75          * </p><p>
76          * The location field can only be used to determine the location of
77          * the key code or character in the current event. It does not include
78          * information about the location of modifiers in the state mask.
79          * </p>
80          *
81          * @see org.eclipse.swt.SWT#LEFT
82          * @see org.eclipse.swt.SWT#RIGHT
83          * @see org.eclipse.swt.SWT#KEYPAD
84          *
85          * @since 3.6
86          */
87         public int keyLocation;
88
89         /**
90          * the state of the keyboard modifier keys and mouse masks
91          * at the time the event was generated.
92          *
93          * @see org.eclipse.swt.SWT#MODIFIER_MASK
94          * @see org.eclipse.swt.SWT#BUTTON_MASK
95          */
96         public int stateMask;
97
98         /**
99          * A flag indicating whether the operation should be allowed.
100          * Setting this field to <code>false</code> will cancel the operation.
101          */
102         public boolean doit;
103
104         static final long serialVersionUID = 3256442491011412789L;
105
106 /**
107  * Constructs a new instance of this class based on the
108  * information in the given untyped event.
109  *
110  * @param e the untyped event containing the information
111  */
112 public KeyEvent(Event e) {
113         super(e);
114         this.character = e.character;
115         this.keyCode = e.keyCode;
116         this.keyLocation = e.keyLocation;
117         this.stateMask = e.stateMask;
118         this.doit = e.doit;
119 }
120
121 /**
122  * Returns a string containing a concise, human-readable
123  * description of the receiver.
124  *
125  * @return a string representation of the event
126  */
127 @Override
128 public String toString() {
129         String string = super.toString ();
130         return string.substring (0, string.length() - 1) // remove trailing '}'
131                 + " character='" + ((character == 0) ? "\\0" : String.valueOf(character)) + "'=0x" + Integer.toHexString(character)
132                 + " keyCode=0x" + Integer.toHexString(keyCode)
133                 + " keyLocation=0x" + Integer.toHexString(keyLocation)
134                 + " stateMask=0x" + Integer.toHexString(stateMask)
135                 + " doit=" + doit
136                 + "}";
137 }
138 }