org.safs.tools.input
Class InputKeysParser

java.lang.Object
  extended by org.safs.tools.input.InputKeysParser

public class InputKeysParser
extends java.lang.Object

See Also:
Robot,
SEP 22, 2008 (JunwuMa) Add NLS 'keyboard' input support. Actually it is not a REAL keyboard input support. Instead it uses an alternative way. NLS characters in an input string will NOT be translated to keystrokes in certain IME, for the reason of 1) too much code points in some Non-English languages (Chinese), 2)a NLS character owns different keystrokes in different IME and 3)keystrokes for a Chinese character relies on IME too much. Two steps for inputting NLS characters. 1. Copy NLS characters to system Clipboard. Add an event: SetClipboardEvent. 2. Add 'Ctrl+V' keyboard event to paste the content in system Clipboard to focused control. Possible drawbacks: Not sure if it can be used by controls that prevents 'Ctrl+V' from Window OS. If yes, a REAL unique hot key (Ctrl+Shift+V ?) may be introduced for doing so on OS level.
JAN 06, 2009 (LeiWang) Modify method parseBraces(): Use standards instead of special to get character mapping. Otherwise {a 4} will not be treated as inputting 'aaaa' because special does not contains mapping of 'a'.
DEC 07, 2010 (LeiWang) Add method antiParse(), parseKeyCode(), getReverseMap(): Convert a list of RobotKeyEvent to a SAFS's key string

Nested Class Summary
 class InputKeysParser.CharInfo
           
 
Field Summary
protected  boolean alt_on
           
protected  boolean ctrl_on
           
protected static java.lang.String DEL
           
protected static java.lang.String END
           
protected static java.lang.String QUOTE
           
protected static java.lang.String SHIFT
           
protected static java.lang.String SHIFT_END_DELETE
           
protected  boolean shift_on
           
protected static java.lang.String SHIFT_PLUS
           
protected static java.lang.String SPACE
           
 
Constructor Summary
InputKeysParser(INIFileReader config)
           
 
Method Summary
protected  void addEvents(java.util.Vector keys, java.lang.String keychar)
           
 java.lang.String antiParse(java.util.List<RobotKeyEvent> keys)
          Note: This method do the opposite work of parseInput(String)
protected  void clearModifiers(java.util.Vector keys)
          Add keyRelease events to the keystroke Vector and clear boolean flags for active modifiers.
protected  void createCommonStrings()
           
protected  java.util.Vector createPasteEvent()
           
 char getAltChar()
           
 char getCtrlChar()
           
 char getEnterChar()
           
protected  int getKeyCode(java.lang.String _char)
          Retrieve the stored "standard" keycode of the provided character.
 char getLeftBraceChar()
           
 char getLeftParenChar()
           
 char getRightBraceChar()
           
 char getRightParenChar()
           
 java.lang.String getSHIFT_END_DELETE()
           
 char getShiftChar()
           
static void main(java.lang.String[] args)
          simple test\debugging only
protected  java.util.Vector parseBraces(java.lang.String content)
          Process the string previously extracted from between braces.
 java.util.Vector parseChars(java.lang.String input)
           
 java.util.Vector parseInput(java.lang.String input)
           
protected  java.util.Vector parseParens(java.lang.String content)
          Process the string previously extracted from between parens.
protected  java.util.Vector parseString(java.lang.String content)
          Convert literal string characters into their corresponding keycodes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

alt_on

protected boolean alt_on

shift_on

protected boolean shift_on

ctrl_on

protected boolean ctrl_on

SHIFT_END_DELETE

protected static java.lang.String SHIFT_END_DELETE

SHIFT

protected static java.lang.String SHIFT

SHIFT_PLUS

protected static java.lang.String SHIFT_PLUS

END

protected static java.lang.String END

DEL

protected static java.lang.String DEL

QUOTE

protected static java.lang.String QUOTE

SPACE

protected static java.lang.String SPACE
Constructor Detail

InputKeysParser

public InputKeysParser(INIFileReader config)
Method Detail

getShiftChar

public char getShiftChar()

getAltChar

public char getAltChar()

getCtrlChar

public char getCtrlChar()

getEnterChar

public char getEnterChar()

getLeftParenChar

public char getLeftParenChar()

getRightParenChar

public char getRightParenChar()

getLeftBraceChar

public char getLeftBraceChar()

getRightBraceChar

public char getRightBraceChar()

getSHIFT_END_DELETE

public java.lang.String getSHIFT_END_DELETE()

createCommonStrings

protected void createCommonStrings()

addEvents

protected void addEvents(java.util.Vector keys,
                         java.lang.String keychar)

antiParse

public java.lang.String antiParse(java.util.List<RobotKeyEvent> keys)
Note: This method do the opposite work of parseInput(String)

Parameters:
keys - List of RobotKeyEvent
Returns:
String: the script string that user use to input
The sring's format should be consistent with specification in CreateUnicodeMap

Ex.
keys = { RobotKeyEvent(KEY_PRESS,KeyEvent.VK_SHIFT), RobotKeyEvent(KEY_PRESS,KeyEvent.VK_A), RobotKeyEvent(KEY_PRESS,KeyEvent.VK_A), RobotKeyEvent(KEY_TYPE,KeyEvent.VK_A), RobotKeyEvent(KEY_TYPE,KeyEvent.VK_B), RobotKeyEvent(KEY_TYPE,KeyEvent.VK_5), RobotKeyEvent(KEY_TYPE,KeyEvent.VK_D), RobotKeyEvent(KEY_RELEASE,KeyEvent.VK_SHIFT) }

Returned string will be AAAB{%}D

parseInput

public java.util.Vector parseInput(java.lang.String input)

parseChars

public java.util.Vector parseChars(java.lang.String input)

getKeyCode

protected int getKeyCode(java.lang.String _char)
Retrieve the stored "standard" keycode of the provided character.

Parameters:
_char - -- String of one char.
Returns:
Integer of keycode OR'd with key modifiers. -1 OR'd with modifiers if the char keycode is not found.

parseString

protected java.util.Vector parseString(java.lang.String content)
Convert literal string characters into their corresponding keycodes. This is normally a number of characters to which a modifier is applied.

Parameters:
content - -- the string of characters to convert to keycodes.
Returns:
Vector of Integer keycodes

parseParens

protected java.util.Vector parseParens(java.lang.String content)
Process the string previously extracted from between parens. This is normally a number of characters to which a modifier is applied.

Parameters:
content - -- the string in between parens ( )
Returns:
Vector of Integer keycodes

parseBraces

protected java.util.Vector parseBraces(java.lang.String content)
Process the string previously extracted from between braces. This is one special character String or a special character String followed by a space and the number of times to repeat it.

Parameters:
content - -- the string in between braces { }
Returns:
Vector of Integer keycodes

clearModifiers

protected void clearModifiers(java.util.Vector keys)
Add keyRelease events to the keystroke Vector and clear boolean flags for active modifiers.

Parameters:
keys - Vector to add keyRelease events to.

createPasteEvent

protected java.util.Vector createPasteEvent()

main

public static void main(java.lang.String[] args)
simple test\debugging only