Satimage Previous | Next
keydown
Home Documentation SmileLab Scripting Customizing graph's interface keydown  
When the user hits a key or a key combination involving the modifiers keys ⇧ ⌥ ⌘ ⇪ and ctrl Smile sends the following event to the script of the active graphic window.
keydown the_object event the_record
the_object is a reference to the owner of the script, the active graphic window.
the_record can contain two fields: character and modifiers.
character is a string, the key which was hit, considering the modifiers. For instance if the user presses ⇧A character is "A", not "a". If the user presses A character is "a".
modifiers is a list of one or several of the following values: shift down (⇧), option down (⌥), command down (⌘), caps lock down (⇪) and control down (ctrl). Note that those values are keywords, not strings.
Example
The example below handles the r (for "reset") and n (for "new") keystrokes; it creates random curves.
on keydown theWindow event theEvent
    if modifiers of theEvent is not {} then return
    if character of theEvent is not in "rn" then return
    if character of theEvent is "r" then
        try
            set v to plot view 1 of theWindow
            delete every curve of v
        end try
        draw theWindow
        return
    end if
    try
        set v to plot view 1 of theWindow
    on error
        set v to make new plot view at theWindow
        set name of v to "\\alpha.sin(x^{\\alpha})"
    end try
    set c to make new curve at end of v
    set f to random number from 0.0 to 2.0
    set formula of c to "" & f & "*sin(x^" & f & ")"
    draw theWindow
end keydown


Import script
To experiment with the script above, proceed as follows.
  • Run first the line below, which will create the window.
    make new graphic window

    Import script
  • Select Graphs ▸ Edit script then choose the window. This will open the graphic window's script.
  • Paste the (longer) script above, then save and close the script window with the File menu.
Now hit n (new) to create curves, r (reset) to clean up the plot.
Copyright ©2008 Paris, Satimage