在RFT中傳送鍵盤按鍵 - inputChars vs. inputkeys

TIB發表於2010-01-17

 

RFT中,inputCharsinputkeys都可以給指定視窗傳送按鍵。

inputKeys

public void inputKeys(java.lang.String keys)

Sends the supplied characters to the associated window. The window is responsible for sending the characters on to the appropriate controls nested in that window. The characters in the given string are interpreted according to the rules documented under ITopWindow.inputKeys.

Specified by:

inputKeys in interface ITopWindow

Parameters:

keys - the characters to be processed by this window

Since:

RFT1.1

 

例如,下面指令碼將通過傳送組合鍵ALT+H以及A鍵,控制選單選擇開啟計算器的關於介面:

        計算器window().click(CAPTION);

        計算器window(ANY,MAY_EXIT).inputKeys("%ha");

       

組合鍵的識別符號包括+^%~(){}:

The characters with special meanings are:
+^%~(){}

The meanings of these special characters are described as follows:

·   Tilde is a special character that is shorthand for the ENTER key:
~ Play back an ENTER  

~表示Enter鍵

·   The following special characters modify the token that follows them:
+ Apply SHIFT to the character that follows immediately   +表示SHIFT鍵
^ Apply CONTROL to the character that follows immediately ^表示CTRL鍵
% Apply ALT to the character that follows immediately     %表示ALT鍵

For example, the following string plays back "ABCD":
"+a+b+c+d"

·   You can use parenthesis to group a set of characters on which the same modifier is applied. For example, the following plays back "ABCD":
"+(abcd)"

可以用()把一組字元括起來,前面的特殊字元對於括起來的一組都生效。

·   To play back a character with special meaning (rather than using it for its special meaning), enclose the character in curly braces. For example, the following string plays back "++++":
"{+}{+}{+}{+}"

用花括號對這些特殊字元進行轉義。

·   You can specify a repeat count by enclosing the character in curly braces, followed by a space and then the count. For example, the following plays back "aaaa":
"{a 4}"

還可以用花括號表示重複指定字元一定的次數。

·   To play back only a key-down event for a character, enclose the character in curly braces, followed by a space and then KeyDn. To play back only a key-up event for a character, enclose the character in curly braces, followed by a space and then KeyUp. For example, the following plays back a complete "a" key-press:
"{a KeyDn}{a KeyUp}"

如果要表示按下或釋放某個按鍵,需要在按鍵後空一個加KeyDn或KeyUp

·   Keys without print representation, for example, backspace, escape, print-screen, and so on, are tool-given names. To play back one of these keys, put its name in curly braces. The names are case-insensitive; for example, you can enter either {TAB} or {tab} and get the same result. Some keys have more than one name; for example, {BACKSPACE} and {BKSP} signify the same key. Following is a list of the names for all the unprintable characters. In this list, synonyms are listed next to each other: (下面是各種功能控制鍵的表示)

{CAPSLOCK} {NUMLOCK} {SCROLLLOCK} {ESCAPE} {ESC} {ENTER} {HELP} {PRTSC} {TAB} {BREAK} {CLEAR} {BACKSPACE} {BS} {BKSP} {DELETE} {DEL} {INSERT} {LEFT} {RIGHT} {UP} {DOWN} {PGUP} {PGDN} {HOME} {END} {F1} {F2} {F3} {F4} {F5} {F6} {F7} {F8} {F9} {F10} {F11} {F12} {F13} {F14} {F15} {F16} {APPS} {Win} {LEFTWIN} {RIGHTWIN} {CTRL} {SHIFT} {ALT} {LEFTCTRL} {LEFTSHIFT} {LEFTALT} {RIGHTCTRL} {RIGHTSHIFT} {RIGHTALT} {ExtDelete} {ExtInsert} {ExtLeft} {ExtRight} {ExtUp} {ExtDown} {ExtPgUp} {ExtPgDn} {ExtHome} {ExtEnd} {NumDelete} {NumInsert} {NumLeft} {NumRight} {NumUp} {NumDown} {NumPgUp} {NumPgDn} {NumHome} {NumEnd} {Num} {Num-} {Num/} {Num+} {Num~} {NumEnter} {Num0} {Num1} {Num2} {Num3} {Num4} {Num5} {Num6} {Num7} {Num8} {Num9} {Num.} >

Example:

Send "AB" to a password text field in classicJava application
passwordText().inputKeys("+a+b");

 

inputChars

inputKeys相反,inputChars傳送的按鍵字元不會被解釋。

 

public void inputChars(java.lang.String keys)

Sends the supplied characters to the associated window. The window is responsible for sending the characters on to the appropriate controls nested in that window. The characters are uninterpreted. For example, inputChars("+a+b") emits "+a+b", in contrast to inputKeys("+a+b"), which interprets the "+" as a shift and emits "AB".

Specified by:

inputChars in interface ITopWindow

Parameters:

keys - The characters to be processed by this window

Since:

RFT1.1

 

 

相關文章