The bind command associates R functions with UI events.

bind_event(tag, event, command)

bind_opts(event, command)

Arguments

tag

the tic_ui object

event

the event to watch for on this object.

The general form of an event is "modifiers-type-detail"

command

R function to run when this even occurs.

Details

bind_opts is used to define binding events within the UI spec.

After the UI is created (with a call to win = render_ui(ui_spec)), events can be bound with bind_event(...).

examples

"c"

keyboard character 'c'

"Control-q"

Key combination CTRL+q

"ButtonPress"

Any button press

"KeyPress"

Any keypress

"Double-Button-1"

Double click on Mouse Button number 1

modifiers

Control, Alt, Shift, Lock, Button1-Button5, Mod1-Mod5, Meta Double, Triple, Quadruple

events

Activate, ButtonPress, Button, ButtonRelease, Circulate, CirculateRequest, Configure, ConfigureRequest, Create, Deactivate, Destroy, Enter, Expose, FocusIn, FocusOut, Gravity, KeyPress, Key, KeyRelease, Leave, Map, MapRequest, Motion, MouseWheel, Property, Reparent, ResizeRequest, Unmap, Visibility

variables

Variables available to the command depend upon the event. See https://www.tcl.tk/man/tcl8.6/TkCmd/bind.html for the full list.

some variables are listed here:

b

The number of the button that was pressed or released. Valid only for ButtonPress and ButtonRelease events.

k

The keycode field from the event. Valid only for KeyPress and KeyRelease events.

K

The keysym corresponding to the event, substituted as a textual string. Valid only for KeyPress and KeyRelease events.

t

time stamp of the event

x,y

indicate the position of the mouse pointer relative to the UI window.

X, Y

indicate the position of the mouse pointer in absolute screen coordinates

D

This reports the delta value of a MouseWheel event. The delta value represents the rotation units the mouse wheel has been moved. The sign of the value represents the direction the mouse wheel was scrolled.

tcl/tk

See tcl/tk documentation for more information on binding commands to events https://www.tcl.tk/man/tcl8.6/TkCmd/bind.html

Examples

if (FALSE) {
# Every mouse press prints coordinates
ui_spec <- tic_window()
win <- render_ui(ui_spec)
bind_event(win, "Button", function(t, x, y, ...) { message(t, ": ", x, ", ", y)})
}