copy text from a GUI textbox field

Asked by andrea on 2012-03-05

Hi, I have a GUI (developed in Java) where I need to copy the text inserted from the user. So my sikuli script should wait until the user type in the value in the relative field then copy the text and save it in a variable. There is a way to do this?
Thanks to all.

Andrea

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2012-03-12
Last query:
2012-03-12
Last reply:
2012-03-05
Best RaiMan (raimund-hocke) said : #1

If this should happen, while the user is still working on the GUI, this will be very tricky to solve or not possible at all.

Why? Main reason: Because you will need the mouse and keyboard to accomplish the task:

click(theEntryField)
wait(0.5)
type("a", KeyModifier.CTRL) # select all text
wait(0.5)
type("c", KeyModifier.CTRL) # copy to clipboard
wait(0.5)
text = Env.getClipboard()

during this piece of code, the user should not use the and the keyboard and mouse. Depending on wether the wait()s are needed with your GUI, the whole action might take 1 to 3 seconds.

--- The second problem to solve: wait, until the user has finished entering text into the field.
Since Sikuli has no features, to act with the GUI as such, it has to be solved, by watching the visual situation of the field or (if it is guaranteed, that the user does not use the keyboard to go to next field) tracking the mouse movement.

visual:
use a change observer, that waits for the user to start changing the visual content of the field and then wait until he does not do it anymore. (tricky, but scriptable)

mouse movement:
wait until the mouse enters the field and then wait until the mouse leaves it again. (scriptable but risky, since the user might accidentally move the mouse away before finishing text entry)

RaiMan (raimund-hocke) said : #2

*** revised because of some typo

If this should happen, while the user is still working on the GUI, this will be very tricky to solve or not possible at all.

Why? Main reason: Because you will need the mouse and keyboard to accomplish the task:

click(theEntryField)
wait(0.5)
type("a", KeyModifier.CTRL) # select all text
wait(0.5)
type("c", KeyModifier.CTRL) # copy to clipboard
wait(0.5)
text = Env.getClipboard()

during this piece of code, the user should not use keyboard and mouse. Depending on wether the wait()s are needed with your GUI, the whole action might take 1 to 3 seconds.

--- The second problem to solve: wait, until the user has finished entering text into the field.
Since Sikuli has no features, to act with the GUI as such, it has to be solved, by watching the visual situation of the field or (if it is guaranteed, that the user does not use the keyboard to go to next field) or by tracking the mouse movement.

visual:
use a change observer, that waits for the user to start changing the visual content of the field and then wait until he does not do it anymore. (tricky, but scriptable)

mouse movement:
wait until the mouse enters the field and then wait until the mouse leaves it again. (scriptable but risky, since the user might accidentally move the mouse away before finishing text entry)

andrea (andrea-merli69) said : #3

Thanks RaiMan, that solved my question.