Combining "focus" and "type" commands

Asked by Mychal Miller

I have a script that opens two command windows, starts a telnet session in each, then sends a sequence of commands to them. There are many occasions when the script sends a command to window cmd_A, then a command to window cmd_B, then to window cmd_A, etc.

Currently, I use the following code:

self.cmd_a.focus()
type("first command" + Key.ENTER)

self.cmd_b.focus()
type("second command" + Key.ENTER)

self.cmd_a.focus()
type("third command" + Key.ENTER)

self.cmd_b.focus()
type("fourth command" + Key.ENTER)
...etc.

Is there a way to shorten this to a single command or stack the commands? Something like:
self.cmd_b.type("command" + Key.ENTER)

I haven't found anything in the documentation that makes me think there is, but if there is it would make my coding a bit neater. If all else fails, I can create a function that takes the window and text as parameters, but since it will be used so often I was hoping for a more efficient way.

Question information

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

If the 2 windows do not overlap completely, you might once calculate a click point (e.g. derived from the app window) in the always visible part of each window, that can be used with type(), which then first would do a click internally.

# once during initialization
w1 = click_point_commandA
w2 = click_point_commandB

# usage later on
type(w1, "command" + Key.ENTER)
type(w2, "command" + Key.ENTER)

If this does not work for you because of e.g. timing problems, you have to implement the function you mentioned already.

Revision history for this message
Mychal Miller (mychaluva) said :
#2

Thanks. In normal usage they will be arranged non-overlapping, but I'd prefer not to build that assumption into the code. My preference is to guide clicks by focusing and finding the click point rather than predefining any click points.

Thanks for the quick response!