Arrow keys on background list field

Cubist at aol.com Cubist at aol.com
Mon Dec 27 19:07:03 EST 2004


sez tsalagi at elohigadugi.org:
>I need some help on my Cherokee Dictionary project. 
>I have my entries on separate cards and a scroll list
>field of dictionary entries on a background group.
>Everything works fine when I use my find field or
>when i click on the entry directly. The problem comes 
>when I try to use the arrow keys to move up or down
>on the list. I am guessing that is because each time
>I change my selection I am moving to a new card. 
>I have tried to change the hilighted line
>on the new card with a handler, but this doesn't
>seem to work either.
>
>Also, the arrow key seems to bring up the last
>card I was on, instead of the next card on the list.
>Sometimes it even brings up the Rev Documentation
>stack if I've been using that recently.
   Seems to me that trapping for the "keyDown" message, or perhaps 
"arrowKey", might be helpful here. Something along these lines should do what you want:

on keyDown Diskey
  put the hilitedLine of me into CurrentLine
  switch DisKey
  case "left"
    # if you want the left arrow to behave the same as the up arrow,
    # remove all the code from this 'fork' of the switch
    put 1 into NextLine
    break
  case "up"
    # note: i don't recall the precise syntax for the value of "the 
hilitedLine",
    # so you may need to tweak the line immediately after this comment
    put max ((CurrentLine - 1), the number of lines in me) into NextLine
    break
  case "right"
    # see comment for the "left" fork of this switch
    put the number of lines in me into NextLine
  case "down"
    # same caveat as for "up"
    put min ((CurrentLine + 1), the number of lines in me) into NextLine
    break
  default
    # this fork of the switch covers everything *but* arrow keys.
    # do as you please with them
  end switch

  if CurrentLine = NextLine then
    # the user is trying to scroll back to before the first line,
    # or else to scroll past the last line. BAD user!
    beep 2
  else
    # let the user scroll normally
    set the hilitedline of me to NextLine
    if DisKey is in "left up" then
      go prev card
    else
      go next card
    end if
  end if
end keyDown

   That handler has not been tested, but its underlying logic (if not its 
*syntax*...) should be okay. Hope this helps...


More information about the use-livecode mailing list