How to know if the arrow key is pressed or not

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
problème
Posts: 77
Joined: Fri Oct 23, 2015 12:03 am

How to know if the arrow key is pressed or not

Post by problème » Wed Nov 25, 2015 10:33 pm

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 

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

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

Post by dunbarx » Thu Nov 26, 2015 12:04 am

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

problème
Posts: 77
Joined: Fri Oct 23, 2015 12:03 am

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

Post by problème » Thu Nov 26, 2015 9:59 am

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

Post Reply