Page 1 of 1

How to know if the arrow key is pressed or not

Posted: Wed Nov 25, 2015 10:33 pm
by problème
Hello,
I have character that when i press left arrow key, i move him to the left and i put a image "imageLeft", when i press right arrow i move him to the right and put a image "imageRight" .
I would want to do, when the character don't move put the image "imageStay"

Code: Select all

on arrowKey d
   moveCha d
end arrowKey

on moveCha d
   if d is "right then
           ...
   else if d is "left" then
           ...
    end if
end moveCha 

Re: How to know if the arrow key is pressed or not

Posted: Thu Nov 26, 2015 12:04 am
by dunbarx
Hi.

If you press the left arrow key, something moves left, and imageLeft is shown?
And if you press the right arrow key, something moves right, and imageRight is shown?

And if you do nothing, you want imageNothing to be shown?

But, er, "something" has to happen to invoke that "doing" of nothing. What might it be? A time interval where no arrow key is pressed? A lunar eclipse?

Craig Newman

Re: How to know if the arrow key is pressed or not

Posted: Thu Nov 26, 2015 9:59 am
by problème
Hello,
I try to do this, apparently it's work for now

Code: Select all

on preOpenCard
put the location of graphic "Rectangle" into mouvCourant 
enMouvement
end preOpenCard

on arrowKey d
   moveCha d
end arrowKey

on moveCha d
   if d is "right then
           ...
           put the location of graphic "Rectangle" into mouvCourant 
   else if d is "left" then
           ...
           put the location of graphic "Rectangle" into mouvCourant 
    end if
end moveCha 

on enMouvement
   if (mouvCourant <> the location of the graphic "Rectangle"  )  then
      ....
   end if 
   send "enMouvement" to me in 500 milliseconds 
end enMouvement

thanks for the help