about App.focus() question

Asked by Kc Liu

About App.focus () use, would like to ask you two questions:
1 How can identify the title of the window in the Chinese text(code)? I want to focus only in the window title Chinese text(code), but with App.focus (), can not successfully focus to them.
2 Is there a way to focus a minimized window? I can not focus with it is minimized windows.

Thanks Again!

Question information

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

--- at 1:
App.focus() only works for ASCII-characters in the moment (see bug 784967)

--- at 2:
on this we have another bug: bug 682281

you might try the workaround:
after firing App.focus() use:

wait(1); type(" ", KEY_ALT); type("x")

this accesses the window menu and opens window

Revision history for this message
Kc Liu (abbe08) said :
#2

Thanks
at 1: I understand.
at 2:
Should again failed to properly express my meaning.
For example:
Suppose I open a notepad and I minimize it.
I can not App.focus () to find it?
Or there are other ways to focus it?

Revision history for this message
Calle Rundgren (c-rundgren) said :
#3

Maybe this is not answering your question, but... I am able to focus on a minimized window by using App.focus(r"full path to .exe")

Try that and maybe it would work. :)

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

taking the following example: (supposing Notepad is closed)

(you might have to fix the type()'s - I am on german Win7)

App("Notepad").open(); wait(1) # opens a new Notepad window
App("Editor").focus() # german: comes up with a different prog-name
type("s", KEY_CTRL); wait(1)
type("testing\n") # to give the window a name (mind overwrite situation)
np = App("testing.txt") # the App instance
Region(np.window()).highlight(2) # the Notepad window
type(" ", KEY_ALT); wait(1); type("n") # the sequence to minimize
wait(2) # it is minimized now

np = App("testing.txt").focus() # we try to focus using a new App object
Region(np.window()).highlight(2) # the Notepad window
# nothing happens, because the window is at (-32000, -32000)
# but it accepts type()'s
type(" ", KEY_ALT); wait(1); type("w") # the sequence to restore the window

the window you want, is restored when minimized.

You could even check the x-value of the window region, to find out, whether it is minimized or not after the App.focus().

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

sorry, have to correct the 1st line of the 2nd part of the snippet:

np = App("testing.txt")
np.focus() # we try to focus using a new App object

Can you help with this problem?

Provide an answer of your own, or ask Kc Liu for more information if necessary.

To post a message you must log in.