app.focus() resulting in negative x and y values

Asked by Yongho Lee on 2017-11-11

So I'm using app.focus() to focus on an application for memu, and it results in an error like this:

[error] Region(-250,-250,125,125) outside any screen - subsequent actions might not work as expected
[error] script [ C:\Users\Yongho Lee\Desktop\GFL\GFL.sikuli ] stopped with error in line 156
[error] java.lang.NullPointerException ( java.lang.NullPointerException )
[error] --- Traceback --- error source first
line: module ( function ) statement
123: main ( focus_window ) while not (memu_window.exists(Pattern('main_menu_home.png').exact())):
145: main ( collect_exped ) focus_window()
[error] --- Traceback --- end --------------

The problematic portion of the code looks like this:

def focus_window():
 global memu_window
 myApp = App.focus("MEmu")
 memu_window = myApp.focusedWindow()
 loop_count = 0
 while not (memu_window.exists(Pattern('main_menu_home.png').exact())):
  myApp = App.focus("MEmu")
  memu_window = myApp.focusedWindow()

It's supposed to focus on the memu window and return back its coordinates to another function.

The error occurs when the code tries to initiate (memu_window.exists(Pattern('main_menu_home.png').exact())), so I'm assuming the problem here is app.focus("MEmu") returning negative values. Why does this happen and how can I fix it?

Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Solved by:
Yongho Lee
Last query:
Last reply:
RaiMan (raimund-hocke) said : #1

Since the App features depend on many system specifics, you have to check every result and in case react accordingly or check what went wrong.

Yongho Lee (moonlee7777) said : #2

Can you elaborate? What do you mean "check every result"? If the coordinates of the app is what you're referring to, it results in Region(-250, -250, 125, 125) no matter what.

Otherwise, how would I check what went wrong? Sorry, new to all this.

Yongho Lee (moonlee7777) said : #3

I also tested it out with just

def testing():


and it resulted in

R[-250,-250 125x125]@S(?) E:Y, T:3.0

So I know for sure App.focusedWinow() is returning negative coordinates. Do you have any idea why?

Yongho Lee (moonlee7777) said : #4

Nevermind I was being retarded
spelled the name of the application wrong