You're on the right track. Just check the mirrored state for each case when the sprite is supposed to switch. When you hit the left key, it has to be mirrored again to switch back.
a$="Ed222"
text 0,0,a$
get image 1,0,0,text width(a$),text height(a$)
cls 0
do
sprite 1,100,100,1
if rightkey()=1 and sprite mirrored(1)=0
mirror sprite 1
endif
if leftkey()=1 and sprite mirrored(1)=1
mirror sprite 1
endif
remstart
uncomment this if you want the sprite to default to
it's original position when neither key is pressed
if leftkey()=0 and rightkey()=0 and sprite mirrored(1)=1
mirror sprite 1
endif
remend
loop
Enjoy your day.