rawkeydown & rawkeyup (was : 2 more questions aboutoperationson text in fields)

jbv jbv.silences at Club-Internet.fr
Mon Aug 2 17:21:54 EDT 2004



"J. Landman Gay" a *crit :

> On 8/2/04 1:56 PM, jbv wrote:
>
>  > BTW rawkeydown and rawkeyup both work, but then, how do you
>  > map the raw keynumber with the corresponding char ?
>  > the numtochar can't be used in this situation...
>
> Good question. I usually only use it when I need to trap specific keys,
> and I build a switch statement around those. If you need to trap every
> key then you may be better off with your other solution. What is the
> goal for this handler?
>

Well, it would be a bit too long to explain...
I guess an example is better (please note that I finally used
a third option - it is not fully implemented yet, but it'll give
you an idea).

Create a new stack with 1 field on it.

Put the following script in the card :

-----

on openCard
  global theString1, theString2, myList
  put "" into theString1
  put "" into theString2
  put "Google,Yahoo,Bravo,Alta Vista" into mylist

  set textfont of fld 1 to "Arial"
  set textstyle of fld 1 to bold

end openCard

on recherche a
  global theString1, theString2, myList
  put number of chars of theString2 into n

  put 0 into c
  repeat with j=1 to (number of items of myList)
    get item j of myList
    if char 1 to n of it = theString2 then
      put j into c
      exit repeat
    end if
  end repeat

  if c=0 then
    put theString2 into fld 1
    set the textcolor of line 1 of fld 1 to "black"
    select after char n of fld 1
  else

    put item j of myList into fld 1
    set the textcolor of line 1 of fld 1 to "100,100,100"
    set the textcolor of char 1 to n of line 1 of fld 1 to "black"
    select after char n of fld 1

  end if
end recherche




----------------------

put the following script in the field :

-------

on rawkeyup which
  global theString1, theString2

  put (number of chars of fld 1)

  if (number of chars of fld 1)=1 then
    set textcolor of line 1 of fld 1 to "black"
  end if

  put fld 1 into theString1

  if theString1 is not "" then
    put "" into theString2
    repeat with i=1 to (number of chars of theString1)
      if the textcolor of char i of fld 1 is "0,0,0" then
        put char i of theString1 after theString2
      else
        exit repeat
      end if
    end repeat

    if theString2 is not "" then
      recherche theString2
    else
      put "" into me
    end if
  end if
end rawkeyup

on returninField
  global theString1, theString2
  put fld 1 into theString1
  put "" into me
end returninField

-----------

Now, click inside the field, and type the letter "G" or "Y"...


JB



More information about the use-livecode mailing list