The keyEvent class in java Programming

A key event is generated when keyboard input occurs.There are three types of key events ,which are identified by these integer constant

KEY_FIRST
Marks the first integer id for the range of key event ids.
KEY_LAST
Marks the last integer id for the range of key event ids.
KEY_PRESSED
The key pressed event type.
KEY_RELEASED
The key released event type.
KEY_TYPED
The key typed event type.

 

Constructor in KeyEvent

KeyEvent(Component, int, long, int, int)

public KeyEvent(Component source, int id, long when, int modifiers, int keyCode, char keyChar)
Constructs a KeyEvent object with the specified source component, type, modifiers, and key.
Parameters: source - the object where the event originated

KeyEvent(Component, int, long, int, int, char) 

Constructs a KeyEvent object with the specified source component, type, modifiers, and key.
public KeyEvent(Component source,int id,long when, int modifiers, int keyCode)

KeyEvent Method

getKeyChar()
Returns the character associated with the key in this event.
getKeyCode()
Returns the integer key-code associated with the key in this event.
getKeyModifiersText(int)
Returns a String describing the modifier key(s), such as "Shift", or "Ctrl+Shift".
getKeyText(int)
Returns a String describing the keyCode, such as "HOME", "F1" or "A". isActionKey() Returns whether or not the key in this event is an "action" key, as defined in Event.java.
paramString()
setKeyChar(char)
setKeyCode(int)
setModifiers(int)


CHAR_UNDEFINED,KEY_PRESSED and KEY_RELEASED events which do not map to a valid

Unicode character do not have a defined keyChar.


VK_0
VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39)
VK_1
VK_2
VK_3
VK_4
VK_5
VK_6
VK_7
VK_8
VK_9

VK_A
VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A)
VK_ACCEPT
VK_ADD
VK_ALT
VK_B
VK_BACK_QUOTE
VK_BACK_SLASH
VK_BACK_SPACE
VK_C
VK_CANCEL
VK_CAPS_LOCK
VK_CLEAR
VK_CLOSE_BRACKET
VK_COMMA
VK_CONTROL
VK_CONVERT
VK_D
VK_DECIMAL
VK_DELETE
VK_DIVIDE
VK_DOWN
VK_E
VK_END
VK_ENTER

0 comments:

Post a Comment

 

learn java programming Copyright © 2011-2012 | Powered by appsackel.org