First of all, reading quickly, here is what happens for me :
After Starting
X = false
Y = false
myState = State0
counter = 0
cout :
XCoord :
After 'A'
X = false
Y = false
myState = State1
counter = 1
cout : ONE TWO
XCoord :
There is a problem I think, counter must not be incremented here, since you are modifying the State and testing the state just after you are entering the second test directly, but it's not a number nor a Return, so you print 'TWO' and increment counter (X==false && counter <5)
After '1'
X = false
Y = false
myState = State1
counter = 2
cout : ONE TWO TWO THREE
XCoord : 1
After '2'
X = false
Y = false
myState = State1
counter = 3
cout : ONE TWO TWO THREE TWO THREE
XCoord : 12
After '3'
X = false
Y = false
myState = State1
counter = 4
cout : ONE TWO TWO THREE TWO THREE TWO THREE
XCoord : 123
After '4'
X = false
Y = false
myState = State1
counter = 5
cout : ONE TWO TWO THREE TWO THREE TWO THREE TWO THREE
XCoord : 1234
After 'Return'
X = true
Y = true
myState = State1
counter = 6
cout : ONE TWO TWO THREE TWO THREE TWO THREE TWO THREE TWO
XCoord : 1234
There is another problem I think, You are testing X and modifying it (to true), just after you are testing X and Y, passig into this second test directly. Maybe you do something special if X and Y are true ? (like stopping checking keypressed events)
Good luck, it's not easy to understand
PS: Do the test in the inverse order of the logic, or return from function after being entered the if statements
EDIT : PPS : Debug step by step too, with your head, a paper and a pencil