logical error, rearrange your code.
your code:
while(...){
if (key...){
if (state...){
...
}}}
should be:
while(...){
if (key...){
//change state skill
}
...
if (state...){
//make your animations, etc
}}