arrowKey

Peter M. Brigham, MD pmbrig at gmail.com
Tue Dec 20 11:29:21 EST 2011


Is there some reason not to do it this way?:

on arrowkey which
   put the loc of button "square" into tRect
   switch which
      case "left"
         subtract 1 from item 1 of tRect
         break
      case "right"
         add 1 to item 1 of tRect
         break
      case "up"
         subtract 1 from item 2 of tRect
         break
      case "down"
         add 1 to item 2 of tRect
         break
      default
         pass arrowkey
         break
   end switch
   set the loc of button "square" to tRect
end arrowkey

Put the handler in an invisible button and insert the button's script as a frontscript on opencard. If you put it into the card script then it will work fine usually, but the problem comes if the user has switched the focus off the card by clicking on some other control, so a frontscript is safer that way. Remember to remove the frontscript on closecard, so it doesn't start intercepting arrowkey messages elsewhere.

-- Peter

Peter M. Brigham
pmbrig at gmail.com
http://home.comcast.net/~pmbrig


On Dec 20, 2011, at 7:49 AM, paolo mazza wrote:

> Thank you Bob. Thank you Mike.. Here it is my code to move a button
> using the arrow keys.
> 
> local tSTARTCONTROL
> 
> on StartControl
>   put "true" into tSTARTCONTROL
>   ControlKeys
> end StartControl
> 
> on StopControl
>   put "false" into tSTARTCONTROL
> end StopControl
> 
> on ControlKeys
>   if keysDown() is "65361" then
>      MoveLeft
>   end if
> 
>   if keysDown() is "65362" then
>      MoveUp
>   end if
> 
>   if keysDown() is "65363" then
>      MoveRight
>   end if
> 
>   if keysDown() is "65364" then
>      MoveDown
>   end if
> 
>   if tSTARTCONTROL is true then
>      send ControlKeys to me in 0.2 sec
>   end if
> end ControlKeys
> 
> on MoveLeft
>   set the left of button "square" to (the left of button "square" - 1 )
> end MoveLeft
> 
> on MoveRight
>   set the left of button "square" to (the left of button "square" + 1 )
> end MoveRight
> 
> on MoveUp
>   set the top of button "square" to (the top of button "square" - 1 )
> end MoveUp
> 
> on MoveDown
>   set the top of button "square" to (the top of button "square" + 1 )
> end MoveDown
> 
> It works !!
> 
> All the best. Paolo
> 
> 
> On Tue, Dec 20, 2011 at 3:04 PM, Mike Bonner <bonnmike at gmail.com> wrote:
>> I saw the other input for this problem, I'm thinking that checking
>> "keysdown()" for the arrow keycodes would be a more reliable solution
>> depending on your needs.
>> 
>> I swear I keep learning new things on this list and in the forums. Luckily
>> I have a horrible memory so I get the bonus of relearning the same thing
>> over and over!
>> 
>> On Tue, Dec 20, 2011 at 4:13 AM, paolo mazza <mazzapaoloitaly at gmail.com>wrote:
>> 
>>> Thank you Mike,
>>> I was able to use your script.
>>> I realize that getting the arrows key is not as trivial as "get the
>>> mouse" or "get the optionKey".
>>> However your script works fine.
>>> Thanks a lot
>>> Paolo
>>> 
>>> On Mon, Dec 19, 2011 at 5:28 PM, Mike Bonner <bonnmike at gmail.com> wrote:
>>>> I'm sure this doesn't cover every possibility but will something like the
>>>> following work?
>>>> 
>>>> -- in the card I put
>>>> on arrowKey pKey
>>>>   set the cKeyDown of this stack to pKey
>>>>   pass arrowKey
>>>> end arrowKey
>>>> 
>>>> on rawKeyUp pKey
>>>>   if pKey is among the items of "65361,65362,65363,65364" then
>>>>      if the cKeyDown of this stack is not empty then set the cKeyDown of
>>>> this stack to empty
>>>>   end if
>>>>   pass rawKeyUp
>>>> end rawKeyUp
>>>> 
>>>> 
>>>> --And in a button I put
>>>> local tRunning
>>>> on mouseUp
>>>>   if tRunning is empty then put false into tRunning
>>>>   put not tRunning into tRunning
>>>>   checkarrow
>>>> end mouseUp
>>>> 
>>>> command checkArrow
>>>>   if tRunning then
>>>>      switch (the cKeyDown of this stack is empty)
>>>>         case false
>>>>            put the cKeyDown of this stack
>>>>            break
>>>>         case true
>>>>            put "No Key is down"
>>>>            break
>>>>      end switch
>>>>      send checkArrow to me in 10 milliseconds
>>>>   end if
>>>> end checkArrow
>>>> 
>>>> Depending on your needs this might be enough. It doesn't handle 2 arrow
>>>> keys being pressed (shouldn't be too bad to modify it so that you can
>>>> handle multiple arrow presses, instead of just checking against ALL arrow
>>>> keycodes could have a property for each direction keycode and only wipe
>>> out
>>>> the specific arrow key that is released)
>>>> 
>>>> To test, set up the stack as described, click the button to start the
>>>> monitoring and then hit your keys. Should show results in the msg box.
>>>> 
>>>> On Mon, Dec 19, 2011 at 7:51 AM, paolo mazza <mazzapaoloitaly at gmail.com
>>>> wrote:
>>>> 
>>>>> Hi All,
>>>>> how can I check if the "arrowKey up" is down or is up ?
>>>>> 
>>>>> For example, for the option Key I can write .. if the optioKey is down
>>>>> then...,  for the mouse I can write ... if the mouse is down then ...
>>>>> 
>>>>> What about  the arrow keys ?
>>>>> 
>>>>> All the best
>>>>> 
>>>>> Paolo
>>>>> 
>>>>> _______________________________________________
>>>>> use-livecode mailing list
>>>>> use-livecode at lists.runrev.com
>>>>> Please visit this url to subscribe, unsubscribe and manage your
>>>>> subscription preferences:
>>>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>>>> 
>>>> _______________________________________________
>>>> use-livecode mailing list
>>>> use-livecode at lists.runrev.com
>>>> Please visit this url to subscribe, unsubscribe and manage your
>>> subscription preferences:
>>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>> 
>>> _______________________________________________
>>> use-livecode mailing list
>>> use-livecode at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your
>>> subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list