Keyboard Input

Keyboard Handlers

 

to get key input, use these events:

 

on keyDown

on keyUp

 

*note: these don't work in behaviors on sprites.  either

1) put into a behavior on a Frame Script, or

2) put into a Movie Script so it will be always active.

 

basic keyboard handler:

 

-- print out keys in the message window

on keydown

  k = key ()

  put k

end

 

 

 

responding to keys:

on keydown

  k = key ()

  if k="a" then

      put "good morning"

  else if k="s" then

      put "good afternoon'

  else if k="d" then

      put "good night"

  end if

end

 

Big sets of if/else statements can be written using a shortcut form, called case of:

 

case variable of

      value1: action 1

      value2: action 2

      value3: action 3

      ...

      otherwise: default action

end case

 

So the above set of if/then's could be written like this:

 

case k of

  "a": put "good morning"

 "b": put "good afternoon"

 "c": put "good night"

 otherwise: put "some other time."

end case