The implications of using type() vs. paste()

Asked by Eugene S

Hi RaiMan,

I was reading your comment to the below question, regarding type() vs. paste() usage:
https://answers.launchpad.net/sikuli/+question/138750

I have also found the below "Best Practice" in Sikuli documentation(in Region section):
Best Practice: As a general guideline, the best choice is to use paste() for readable text and type() for action keys like TAB, ENTER, ESC, .... Use one type() for each key or key combination and be aware, that in some cases a short wait() after a type() might be necessary to give the target application some time to react and be prepared for the next Sikuli action.

So I just wanted to know what could be the implications of using type() instead of paste()? I use strings like below for a while now and never had any problems with it.

type("\t" + dob + "\t" + "2 Hay Street" + "\t" + "\t" + "Sydney" + "\t")

I guess that I can't use such input line using paste()?
It is also mentioned that concatenating should not be done as well. Is that correct in such case? What could go wrong with such implementation? Do I have to split each command to a separate line?

Thanks!
Eugene

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
RaiMan Edit question
Solved by:
Eugene S
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

using type() is perfect as long as the used characters produce what you want in the GUI and as long as included TAB (\t) and/or ENTER (\n) and/or other Key.XXX work as expected.

There are 2 common problems:
1. in non US environments, many characters are not produced as expected, because type() only works correctly with US-qwerty keyboard layout.
2. the function keys are not accepted by the GUI, because type() sends the keys too fast.

at 1: the solution is to use paste() for the text parts and type() for the function keys

at 2: normally it is sufficient, to insert some wait()s. For that you have to split up the type().

Conclusion: All is ok, if it works. The above mentioned recommendation is for people new to Sikuli, that do not have any insight yet.
Looking at the questions and bugs: problems with type() came up very often since the beginning of Sikuli.

BTW: I will revise type() and paste(), to accept this key notation as part of a string:
write(#T.dob#3T.2 Hay Street#T.#T3.Sydney#T.)

so Key.TAB will be #T. or #TAB. with the general form
#n1XXXn2.
n1 and n2 will be numbers 1 to 9 that result in a wait of nx*100msecs waiting before/after pressing the function key

... and there will be a repeat factor:
#3*3T5.
would be the same as:
wait(0.3)
type(Key.TAB)
wait(0.5)
type(Key.TAB)
wait(0.5)
type(Key.TAB)
wait(0.5)

Revision history for this message
Eugene S (shragovich) said :
#2

Thanks for the answer RaiMan!

Oh, that would be great!
When are all these features are expected?

Revision history for this message
RaiMan (raimund-hocke) said :
#3

the version 1.1 is planned to be released in December this year, but there will be beta versions in between.