- Swing 教程
- Swing - 首页
- Swing - 概述
- Swing - 环境
- Swing - 控件
- Swing - 事件处理
- Swing - 事件类
- Swing - 事件监听器
- Swing - 事件适配器
- Swing - 布局
- Swing - 菜单
- Swing - 容器
- Swing 有用资源
- Swing - 快速指南
- Swing - 有用资源
- Swing - 讨论
Swing - KeyEvent 类
输入字符时会生成键盘事件。有三种类型的键盘事件,由整数常量表示。
- KEY_PRESSED
- KEY_RELASED
- KEY_TYPED
类声明
以下是java.awt.event.KeyEvent类的声明:
public class KeyEvent extends InputEvent
字段
以下是java.awt.InputEvent类的字段:
static char CHAR_UNDEFINED - KEY_PRESSED 和 KEY_RELEASED 事件不映射到有效的 Unicode 字符,对于 keyChar 值使用此值。
static int KEY_FIRST - 用于键盘事件的 ID 范围中的第一个数字。
static int KEY_LAST - 用于键盘事件的 ID 范围中的最后一个数字。
static int KEY_LOCATION_LEFT - 指示按下或释放的键位于左侧键位置(此键可能有多个位置)的常量。
static int KEY_LOCATION_NUMPAD - 指示键盘事件源自数字键盘或与数字键盘对应的虚拟键的常量。
static int KEY_LOCATION_RIGHT - 指示按下或释放的键位于右侧键位置(此键可能有多个位置)的常量。
static int KEY_LOCATION_STANDARD - 指示按下或释放的键不区分键的左侧或右侧版本,并且没有源自数字键盘(或没有源自与数字键盘对应的虚拟键)的常量。
static int KEY_LOCATION_UNKNOWN - 指示 keyLocation 不确定或不相关的常量。
static int KEY_PRESSED - “键按下”事件。
static int KEY_RELEASED - “键释放”事件。
static int KEY_TYPED - “键入”事件。
static int VK_0 - VK_0 到 VK_9 与 ASCII '0' 到 '9' 相同 (0×30 - 0×39)
static int VK_1
static int VK_2
static int VK_3
static int VK_4
static int VK_5
static int VK_6
static int VK_7
static int VK_8
static int VK_9
static int VK_A - VK_A 到 VK_Z 与 ASCII 'A' 到 'Z' 相同 (0×41 - 0×5A)
static int VK_ACCEPT - 接受或提交功能键的常量。
static int VK_ADD
static int VK_AGAIN
static int VK_ALL_CANDIDATES - 所有候选项功能键的常量。
static int VK_ALPHANUMERIC - 字母数字功能键的常量。
static int VK_ALT
static int VK_ALT_GRAPH - AltGraph 功能键的常量。
static int VK_AMPERSAND
static int VK_ASTERISK
static int VK_AT - "@" 键的常量。
static int VK_B
static int VK_BACK_QUOTE
static int VK_BACK_SLASH - 反斜杠键 "\" 的常量
static int VK_BACK_SPACE
static int VK_BEGIN - 开始键的常量。
static int VK_BRACELEFT
static int VK_BRACERIGHT
static int VK_C
static int VK_CANCEL
static int VK_CAPS_LOCK
static int VK_CIRCUMFLEX - "^" 键的常量。
static int VK_CLEAR
static int VK_CLOSE_BRACKET - 右方括号键 "]" 的常量。
static int VK_CODE_INPUT - 代码输入功能键的常量。
static int VK_COLON - ":" 键的常量。
static int VK_COMMA - 逗号键 "," 的常量。
static int VK_COMPOSE - 组合功能键的常量。
static int VK_CONTEXT_MENU - Microsoft Windows 上下文菜单键的常量。
static int VK_CONTROL
static int VK_CONVERT - 转换功能键的常量。
static int VK_COPY
static int VK_CUT
static int VK_D
static int VK_DEAD_ABOVEDOT
static int VK_DEAD_ABOVERING
static int VK_DEAD_ACUTE
static int VK_DEAD_BREVE
static int VK_DEAD_CARON
static int VK_DEAD_CEDILLA
static int VK_DEAD_CIRCUMFLEX
static int VK_DEAD_DIAERESIS
static int VK_DEAD_DOUBLEACUTE
static int VK_DEAD_GRAVE
static int VK_DEAD_IOTA
static int VK_DEAD_MACRON
static int VK_DEAD_OGONEK
static int VK_DEAD_SEMIVOICED_SOUND
static int VK_DEAD_TILDE
static int VK_DEAD_VOICED_SOUND
static int VK_DECIMAL
static int VK_DELETE
static int VK_DIVIDE
static int VK_DOLLAR - "$" 键的常量。
static int VK_DOWN - 非数字键盘向下箭头键的常量。
static int VK_E
static int VK_END
static int VK_ENTER
static int VK_EQUALS - 等号键 "=" 的常量
static int VK_ESCAPE
static int VK_EURO_SIGN - 欧元货币符号键的常量。
static int VK_EXCLAMATION_MARK - "!" 键的常量。
static int VK_F
static int VK_F1 - F1 功能键的常量。
static int VK_F10 - F10 功能键的常量。
static int VK_F11 - F11 功能键的常量。
static int VK_F12 - F12 功能键的常量。
static int VK_F13 - F13 功能键的常量。
static int VK_F14 - F14 功能键的常量。
static int VK_F15 - F15 功能键的常量。
static int VK_F16 - F16 功能键的常量。
static int VK_F17 - F17 功能键的常量。
static int VK_F18 - F18 功能键的常量。
static int VK_F19 - F19 功能键的常量。
static int VK_F2 - F2 功能键的常量。
static int VK_F20 - F20 功能键的常量。
static int VK_F21 - F21 功能键的常量。
static int VK_F22 - F22 功能键的常量。
static int VK_F23 - F23 功能键的常量。
static int VK_F24 - F24 功能键的常量。
static int VK_F3 - F3 功能键的常量。
static int VK_F4 - F4 功能键的常量。
static int VK_F5 - F5 功能键的常量。
static int VK_F6 - F6 功能键的常量。
static int VK_F7 - F7 功能键的常量。
static int VK_F8 - F8 功能键的常量。
static int VK_F9 - F9 功能键的常量。
static int VK_FINAL
static int VK_FIND
static int VK_FULL_WIDTH - 全角字符功能键的常量。
static int VK_G
static int VK_GREATER
static int VK_H
static int VK_HALF_WIDTH - 半角字符功能键的常量。
static int VK_HELP
static int VK_HIRAGANA - 平假名功能键的常量。
static int VK_HOME
static int VK_I
static int VK_INPUT_METHOD_ON_OFF - 输入法开/关键的常量。
static int VK_INSERT
static int VK_INVERTED_EXCLAMATION_MARK - 倒置感叹号键的常量。
static int VK_J
static int VK_JAPANESE_HIRAGANA - 日语平假名功能键的常量。
static int VK_JAPANESE_KATAKANA - 日语片假名功能键的常量。
static int VK_JAPANESE_ROMAN - 日语罗马字功能键的常量。
static int VK_K
static int VK_KANA
static int VK_KANA_LOCK - 锁定假名功能键的常量。
static int VK_KANJI
static int VK_KATAKANA - 片假名功能键的常量。
static int VK_KP_DOWN - 数字键盘向下箭头键的常量。
static int VK_KP_LEFT - 数字键盘向左箭头键的常量。
static int VK_KP_RIGHT - 数字键盘向右箭头键的常量。
static int VK_KP_UP - 数字键盘向上箭头键的常量。
static int VK_L
static int VK_LEFT - 非数字键盘向左箭头键的常量。
static int VK_LEFT_PARENTHESIS - "(" 键的常量。
static int VK_LESS
static int VK_M
static int VK_META
static int VK_MINUS - 减号键 "-" 的常量
static int VK_MODECHANGE
static int VK_MULTIPLY
static int VK_N
static int VK_NONCONVERT - 不要转换功能键的常量。
static int VK_NUM_LOCK
static int VK_NUMBER_SIGN - "#" 键的常量。
static int VK_NUMPAD0
static int VK_NUMPAD1
static int VK_NUMPAD2
static int VK_NUMPAD3
static int VK_NUMPAD4
static int VK_NUMPAD5
static int VK_NUMPAD6
static int VK_NUMPAD7
static int VK_NUMPAD8
static int VK_NUMPAD9
static int VK_O
static int VK_OPEN_BRACKET - 左方括号键 "[" 的常量
static int VK_P
static int VK_PAGE_DOWN
static int VK_PAGE_UP
static int VK_PASTE
static int VK_PAUSE
static int VK_PERIOD - 句号键 "." 的常量。
static int VK_PLUS - "+" 键的常量。
static int VK_PREVIOUS_CANDIDATE - 上一个候选项功能键的常量。
static int VK_PRINTSCREEN
static int VK_PROPS
static int VK_Q
static int VK_QUOTE
static int VK_QUOTEDBL
static int VK_R
static int VK_RIGHT - 非数字键盘向右箭头键的常量。
static int VK_RIGHT_PARENTHESIS - ")" 键的常量。
static int VK_ROMAN_CHARACTERS - 罗马字符功能键的常量。
static int VK_S
static int VK_SCROLL_LOCK
static int VK_SEMICOLON - 分号键 ";" 的常量。
static int VK_SEPARATER - 此常量已过时,仅出于向后兼容性而包含。
static int VK_SEPARATOR - 数字键盘分隔符键的常量。
static int VK_SHIFT
static int VK_SLASH - 正斜杠键 "/" 的常量
static int VK_SPACE
static int VK_STOP
static int VK_SUBTRACT
static int VK_T
static int VK_TAB
static int VK_U
static int VK_UNDEFINED - 此值用于指示 keyCode 未知。
static int VK_UNDERSCORE - "_" 键的常量。
static int VK_UNDO
static int VK_UP - 非数字键盘向上箭头键的常量。
static int VK_V
static int VK_W
static int VK_WINDOWS - Microsoft Windows "Windows" 键的常量。
static int VK_X
static int VK_Y
static int VK_Z
类构造函数
| 序号 | 构造函数及描述 |
|---|---|
| 1 |
KeyEvent(Component source, int id, long when, int modifiers, int keyCode) 已弃用。自 JDK1.1 起 |
| 2 |
KeyEvent(Component source, int id, long when, int modifiers, int keyCode, char keyChar) 构造一个 KeyEvent 对象。 |
| 3 |
KeyEvent(Component source, int id, long when, int modifiers, int keyCode, char keyChar, int keyLocation) |
类方法
| 序号 | 方法 & 描述 |
|---|---|
| 1 |
char getKeyChar() 返回与此事件中键关联的字符。 |
| 2 |
int getKeyCode() 返回与此事件中键关联的整数 keyCode。 |
| 3 |
int getKeyLocation() 返回起源于此键盘事件的键的位置。 |
| 4 |
static String getKeyModifiersText(int modifiers) 返回一个描述修饰键(例如“Shift”或“Ctrl+Shift”)的字符串。 |
| 5 |
static String getKeyText(int keyCode) 返回一个描述 keyCode 的字符串,例如“HOME”、“F1”或“A”。 |
| 6 |
boolean isActionKey() 返回此事件中的键是否为“操作”键。 |
| 7 |
String paramString() 返回一个参数字符串,用于标识此事件。 |
| 8 |
void setKeyChar(char keyChar) 设置 keyChar 值以指示逻辑字符。 |
| 9 |
void setKeyCode(int keyCode) 设置 keyCode 值以指示物理键。 |
| 10 |
void setModifiers(int modifiers) 已弃用。自 JDK1.1.4 起。 |
继承的方法
此类继承自以下类:
- java.awt.event.InputEvent
- java.awt.event.ComponentEvent
- java.awt.AWTEvent
- java.util.EventObject
- java.lang.Object