If you add “focused” to your overMyWindow if statement, then it should return only if the sketch is focused.