GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • @maxgraph/core

This view

  • Original page
  • New address

GeezerVison is showing maxgraph.github.io — KeyHandler | @maxgraph/core

  • KeyHandler

Class KeyHandler

Event handler that listens to keystroke events. This is not a singleton, however, it is normally only required once if the target is the document element (default).

This handler installs a key event listener in the topmost DOM node and processes all events that originate from descendants of AbstractGraph.container or from the topmost DOM node. The latter means that all unhandled keystrokes are handled by this object regardless of the focused state of the graph.

Example

The following example creates a key handler that listens to the delete key (46) and deletes the selection cells if the graph is enabled.

const keyHandler = new KeyHandler(graph);
keyHandler.bindKey(46, () => {
if (graph.isEnabled()) {
graph.removeCells();
}
});

Keycodes

See http://tinyurl.com/yp8jgl or http://tinyurl.com/229yqw for a list of keycodes or install a key event listener into the document element and print the key codes of the respective events to the console.

To support the Command key and the Control key on the Mac, the following code can be used.

keyHandler.getFunction = function (evt) {
if (evt) {
return (InternalEvent.isControlDown(evt) || (Client.IS_MAC && evt.metaKey))
? this.controlKeys[evt.keyCode]
: this.normalKeys[evt.keyCode];
}
return null;
};
  • Defined in view/handler/KeyHandler.ts:69
Index

Constructors

constructor

Properties

controlKeys controlShiftKeys enabled graph keydownHandler normalKeys shiftKeys target

Methods

bindControlKey bindControlShiftKey bindKey bindShiftKey escape getFunction isControlDown isEnabled isEnabledForEvent isEventIgnored isGraphEvent keyDown onDestroy setEnabled

Constructors

constructor

  • new KeyHandler(graph: AbstractGraph, target?: Element | null): KeyHandler

    Constructs an event handler that executes functions bound to specific keystrokes.

    Parameters

    • graph: AbstractGraph

      Reference to the associated AbstractGraph.

    • target: Element | null = null

      Optional reference to the event target. If null, the document element is used as the event target, that is, the object where the key event listener is installed.

    Returns KeyHandler

    • Defined in view/handler/KeyHandler.ts:77

Properties

controlKeys

controlKeys: { [key: number]: Function } = {}

Maps from keycodes to functions for pressed control keys.

  • Defined in view/handler/KeyHandler.ts:116

controlShiftKeys

controlShiftKeys: { [key: number]: Function } = {}

Maps from keycodes to functions for pressed control and shift keys.

  • Defined in view/handler/KeyHandler.ts:121

enabled

enabled: boolean = true

Specifies if events are handled.

Default

true
  • Defined in view/handler/KeyHandler.ts:127

graph

graph: AbstractGraph | null = null

Reference to the AbstractGraph associated with this handler.

  • Defined in view/handler/KeyHandler.ts:96

keydownHandler

keydownHandler: ((event: KeyboardEvent) => void) | null = null
  • Defined in view/handler/KeyHandler.ts:91

normalKeys

normalKeys: { [key: number]: Function } = {}

Maps from keycodes to functions for non-pressed control keys.

  • Defined in view/handler/KeyHandler.ts:106

shiftKeys

shiftKeys: { [key: number]: Function } = {}

Maps from keycodes to functions for pressed shift keys.

  • Defined in view/handler/KeyHandler.ts:111

target

target: Element | null = null

Reference to the target DOM, that is, the DOM node where the key event listeners are installed.

  • Defined in view/handler/KeyHandler.ts:101

Methods

bindControlKey

  • bindControlKey(code: number, funct: Function): void

    Binds the specified keycode to the given function. This binding is used if the control key is pressed.

    Parameters

    • code: number

      Integer that specifies the keycode.

    • funct: Function

      JavaScript function that takes the key event as an argument.

    Returns void

    • Defined in view/handler/KeyHandler.ts:175

bindControlShiftKey

  • bindControlShiftKey(code: number, funct: Function): void

    Binds the specified keycode to the given function. This binding is used if the control and shift key are pressed.

    Parameters

    • code: number

      Integer that specifies the keycode.

    • funct: Function

      JavaScript function that takes the key event as an argument.

    Returns void

    • Defined in view/handler/KeyHandler.ts:186

bindKey

  • bindKey(code: number, funct: Function): void

    Binds the specified keycode to the given function. This binding is used if the control key is not pressed.

    Parameters

    • code: number

      Integer that specifies the keycode.

    • funct: Function

      JavaScript function that takes the key event as an argument.

    Returns void

    • Defined in view/handler/KeyHandler.ts:153

bindShiftKey

  • bindShiftKey(code: number, funct: Function): void

    Binds the specified keycode to the given function. This binding is used if the shift key is pressed.

    Parameters

    • code: number

      Integer that specifies the keycode.

    • funct: Function

      JavaScript function that takes the key event as an argument.

    Returns void

    • Defined in view/handler/KeyHandler.ts:164

escape

  • escape(evt: KeyboardEvent): void

    Hook to process ESCAPE keystrokes. This implementation invokes AbstractGraph.stopEditing to cancel the current editing, connecting and/or other ongoing modifications.

    Parameters

    • evt: KeyboardEvent

      Key event that represents the keystroke. Possible keycode in this case is 27 (ESCAPE).

    Returns void

    • Defined in view/handler/KeyHandler.ts:310

getFunction

  • getFunction(evt: KeyboardEvent): Function | null

    Returns the function associated with the given key event or null if no function is associated with the given event.

    Parameters

    • evt: KeyboardEvent

      Key event whose associated function should be returned.

    Returns Function | null

    • Defined in view/handler/KeyHandler.ts:205

isControlDown

  • isControlDown(evt: KeyboardEvent): boolean

    Returns true if the control key is pressed. This uses Event#isControlDown.

    Parameters

    • evt: KeyboardEvent

      Key event whose control key pressed state should be returned.

    Returns boolean

    • Defined in view/handler/KeyHandler.ts:195

isEnabled

  • isEnabled(): boolean

    Returns true if events are handled. This implementation returns enabled.

    Returns boolean

    • Defined in view/handler/KeyHandler.ts:133

isEnabledForEvent

  • isEnabledForEvent(evt: KeyboardEvent): boolean | undefined

    Returns true if the given event should be handled. isEventIgnored is called later if the event is not an escape keystroke, in which case escape is called.

    This implementation returns true if AbstractGraph.isEnabled returns true for both, this handler and graph, if the event is not consumed and if isGraphEvent returns true.

    Parameters

    • evt: KeyboardEvent

      Key event that represents the keystroke.

    Returns boolean | undefined

    • Defined in view/handler/KeyHandler.ts:285

isEventIgnored

  • isEventIgnored(evt: KeyboardEvent): boolean

    Returns true if the given keystroke should be ignored. This returns AbstractGraph.isEditing.

    Parameters

    • evt: KeyboardEvent

      Key event that represents the keystroke.

    Returns boolean

    • Defined in view/handler/KeyHandler.ts:299

isGraphEvent

  • isGraphEvent(evt: KeyboardEvent): boolean

    Returns true if the event should be processed by this handler. That is, if the event source is either the target, one of its direct children, or a descendant of the AbstractGraph.container, or the CellEditorHandler plugin of the graph.

    Parameters

    • evt: KeyboardEvent

      Key event that represents the keystroke.

    Returns boolean

    • Defined in view/handler/KeyHandler.ts:229

keyDown

  • keyDown(evt: KeyboardEvent): void

    Handles the event by invoking the function bound to the respective keystroke if isEnabledForEvent returns true for the given event and if isEventIgnored returns false, except for escape for which isEventIgnored is not invoked.

    Parameters

    • evt: KeyboardEvent

      Key event that represents the keystroke.

    Returns void

    • Defined in view/handler/KeyHandler.ts:255

onDestroy

  • onDestroy(): void

    Destroys the handler and all its references into the DOM. This does normally not need to be called, it is called automatically when the window unloads (in IE).

    Returns void

    • Defined in view/handler/KeyHandler.ts:321

setEnabled

  • setEnabled(enabled: boolean): void

    Enables or disables event handling by updating enabled.

    Parameters

    • enabled: boolean

      Boolean that specifies the new enabled state.

    Returns void

    • Defined in view/handler/KeyHandler.ts:142

Settings

Member Visibility
  • Protected
  • Inherited
Theme

On This Page

ExampleKeycodes
Constructors
constructor
Properties
controlKeyscontrolShiftKeysenabledgraphkeydownHandlernormalKeysshiftKeystarget
Methods
bindControlKeybindControlShiftKeybindKeybindShiftKeyescapegetFunctionisControlDownisEnabledisEnabledForEventisEventIgnoredisGraphEventkeyDownonDestroysetEnabled
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.