bind {allwindows} [<key-sequence>] ["<gnuplot commands>"] bind <key-sequence> "" reset bind
The bind allows defining or redefining a hotkey, i.e. a sequence of gnuplot commands which will be executed when a certain key or key sequence is pressed while the driver's window has the input focus. Note that bind is only available if gnuplot was compiled with mouse support and it is used by all mouse-capable terminals. A user-specified binding supersedes any builtin bindings, except that <space> and 'q' cannot normally be rebound. For an exception, see bind space.
Only mouse button 1 can be bound, and only for 2D plots.
You get the list of all hotkeys by typing show bind or bind or by typing the hotkey 'h' in the graph window.
Key bindings are restored to their default state by reset bind.
Note that multikey-bindings with modifiers must be given in quotes.
Normally hotkeys are only recognized when the currently active plot window has focus. bind allwindows <key> ... (short form: bind all <key> ...) causes the binding for <key> to apply to all gnuplot plot windows, active or not. In this case gnuplot variable MOUSE_KEY_WINDOW is set to the ID of the originating window, and may be used by the bound command.
Examples:
- set bindings:
bind a "replot" bind "ctrl-a" "plot x*x" bind "ctrl-alt-a" 'print "great"' bind Home "set view 60,30; replot" bind all Home 'print "This is window ",MOUSE_KEY_WINDOW'
- show bindings:
bind "ctrl-a" # shows the binding for ctrl-a bind # shows all bindings show bind # show all bindings
- remove bindings:
bind "ctrl-alt-a" "" # removes binding for ctrl-alt-a (note that builtins cannot be removed) reset bind # installs default (builtin) bindings
- bind a key to toggle something:
v=0 bind "ctrl-r" "v=v+1;if(v%2)set term x11 noraise; else set term x11 raise"
Modifiers (ctrl / alt) are case insensitive, keys not:
ctrl-alt-a == CtRl-alT-a ctrl-alt-a != ctrl-alt-A
List of modifiers (alt == meta):
ctrl, alt, shift (only valid for Button1)
List of supported special keys:
"BackSpace", "Tab", "Linefeed", "Clear", "Return", "Pause", "Scroll_Lock", "Sys_Req", "Escape", "Delete", "Home", "Left", "Up", "Right", "Down", "PageUp", "PageDown", "End", "Begin",
"KP_Space", "KP_Tab", "KP_Enter", "KP_F1", "KP_F2", "KP_F3", "KP_F4", "KP_Home", "KP_Left", "KP_Up", "KP_Right", "KP_Down", "KP_PageUp", "KP_PageDown", "KP_End", "KP_Begin", "KP_Insert", "KP_Delete", "KP_Equal", "KP_Multiply", "KP_Add", "KP_Separator", "KP_Subtract", "KP_Decimal", "KP_Divide",
"KP_1" - "KP_9", "F1" - "F12"
The following are window events rather than actual keys
"Button1" "Close"
See also help for mouse.
plot 'something' pause mouse if (exists("MOUSE_BUTTON")) call 'something_else'; \ else print "No mouse click."
It is also possible to track keystrokes in the plot window using the mousing code.
plot 'something' pause mouse keypress print "Keystroke ", MOUSE_KEY, " at ", MOUSE_X, " ", MOUSE_Y
When pause mouse keypress is terminated by a keypress, then MOUSE_KEY will contain the ascii character value of the key that was pressed. MOUSE_CHAR will contain the character itself as a string variable. If the pause command is terminated abnormally (e.g. by ctrl-C or by externally closing the plot window) then MOUSE_KEY will equal -1.
Note that after a zoom by mouse, you can read the new ranges as GPVAL_X_MIN, GPVAL_X_MAX, GPVAL_Y_MIN, and GPVAL_Y_MAX, see gnuplot-defined variables.
Copyright 1986 - 1993, 1998, 2004 Thomas Williams, Colin Kelley
Distributed under the gnuplot license (rights to distribute modified versions are withheld).