It seems that the variables which screenx and screeny use to calculate positions are not updated at the instant focus is moved. See my script for an example.
Its graals scrolling function. It works fine on the corners when the focus isn't being moved. It forced me to use layers 1 and 2 for drawing text on Era to show the HP/Armor. Yich.