Resetting coordinates is next to impossible, but there is a solution to this problem: The Stylus.Down() function.
Here's a fixed version of your code:
require("functions.inc.lua")
SCREEN_TOP = 1
SCREEN_BOTTOM = 0
BGTopText = Screen.LoadTextBG()
BGBotText = Screen.LoadTextBG()
Screen.Initialize( SCREEN_TOP, BGTopText )
Screen.Initialize( SCREEN_BOTTOM, BGBotText )
BGTopText:PrintXY( 1, 5, "Hi "..DSLua.UserName().."!" )
BGTopText:PrintXY( 3, 5, "Welcome to SKETCH" )
while Pads.Start() == false do
BGBotText:PrintXY(1,2,"Click for Keyboard-Mode")
BGBotText:PrintXY(1,5,"Click for Stylus-Mode")
BGBotText:PrintXY(1,8,"Click for Stylus-Line-Mode")
while true do
DSLua.LidCloseAction()
if Stylus.Down() then
if stylusInTextBox(1, 1, 5, 3) then
DSLua.WaitForNoKey()
BGBotText:Clear()
dofile("sketch_keyboard.lua")
break
end
if stylusInTextBox(1, 4, 5, 6) then
DSLua.WaitForNoStylus()
BGBotText:Clear()
dofile("sketch_stylus_free.lua")
break
end
if stylusInTextBox(1, 7, 5, 9) then
DSLua.WaitForNoStylus()
BGBotText:Clear()
dofile("sketch_stylus_lines.lua")
break
end
end
end
end
The simple addition was to check whether the Stylus is on the screen or not. If not, the stylusInBox commands aren't even run, so the old coordinates are not processed.