An IInputMode that recognizes simple key events and invokes a registered action.
Remarks
Examples
KeyboardInputMode
is installed as a child mode of a GraphEditorInputMode or GraphViewerInputMode and can be retrieved from the keyboardInputMode property.const keyboardInputMode = mode.keyboardInputMode
// Execute the command if the Insert key is pressed
graphEditorInputMode.keyboardInputMode.addKeyBinding(
'Insert',
ModifierKeys.NONE,
() => {
graphEditorInputMode.createNode(
graphEditorInputMode.graphComponent!.viewport.center,
)
},
)
// Fit graph into viewport if the Enter key is pressed
graphEditorInputMode.keyboardInputMode.addRecognizerBinding(
(evt) => evt instanceof KeyEventArgs && evt.key === 'Enter',
() => graphComponent.fitGraphBounds(),
)
Type Details
- yFiles module
- view
See Also
Constructors
Parameters
A map of options to pass to the method.
- priority - number
- exclusive - boolean
- A value indicating whether this mode will be the only one running when it has the mutex. This option sets the exclusive property on the created object.
- enabled - boolean
- The enabled state of this input mode. This option sets the enabled property on the created object.
Properties
Gets the canvas instance this mode is currently installed in or null
.
Gets the installed controller.
Gets or sets the enabled state of this input mode.
Remarks
Examples
mode.keyboardInputMode.enabled = false
See Also
Gets or sets a value indicating whether this mode will be the only one running when it has the mutex.
Remarks
The value of this property will be delegated to the exclusive property of the controller.
If this mode is marked as exclusive and has the mutex, all other modes added to the same MultiplexingInputMode will be deactivated. Otherwise, it will always run concurrently with all other modes.
Retrieves the IInputModeContext this mode has been installed in.
Remarks
null
if this mode is currently not installed.Gets the priority of this input mode.
Remarks
See Also
Implements
Methods
addCommandBinding
(command: Command, executedHandler: function(ExecuteCommandArgs):void, canExecuteHandler?: function(CanExecuteCommandArgs):void) : KeyboardInputModeBindingAdds a Command and associated execution handlers to this instance.
Remarks
When a command is already registered (which is the case for most commands), the new binding is executed first, followed by the previously registered bindings. The built-in binding is executed last. To prevent execution of earlier registrations, let the executedHandler
set handled on the ExecuteCommandArgs to true
.
The command will not be allowed to execute if this mode is disabled or inactive.
Parameters
A map of options to pass to the method.
- command - Command
- The command to register handlers with.
- executedHandler - function(ExecuteCommandArgs):void
- The handler for the execution.
Signature Details
function(args: ExecuteCommandArgs)
Function signature for a callback that executes a given Command for the given parameter set in theargs
.Parameters
- args - ExecuteCommandArgs
- The arguments which contain the
and the optional . Handler implementations have to set to true
to indicate that the action was handled and executed successfully by this handler. The list of execution handlers will be traversed for all handlers until the first handler setsto true
.
- canExecuteHandler - function(CanExecuteCommandArgs):void
- The handler that determines whether the
command
can be executed,null
if the command can always be executed.Signature Details
function(args: CanExecuteCommandArgs)
Function signature for a callback that determines whether a given Command can be executed for the given parameter set in theargs
.Parameters
- args - CanExecuteCommandArgs
- The arguments which contain the
and the optional . Handler implementations have to set to true
to indicate that the command can be executed. Handler implementations have to settrue
to indicate that the action was handled.
Returns
- ↪KeyboardInputModeBinding
- A token for the newly created command binding that can be used to later remove this binding from this instance again.
See Also
addKeyBinding
(key: string, modifiers: ModifierKeys, action: function():void) : KeyboardInputModeBindingAdds an action for a specific key down event to this mode.
Remarks
Parameters
A map of options to pass to the method.
- key - string
- The key that should be recognized. The value of a key corresponds to KeyboardEvent.key. It is treated as case-insensitive and the
modifiers
are handled separately. - modifiers - ModifierKeys
- The modifiers that should be recognized when the key is pressed.
- action - function():void
- The action that will be invoked if the given key down event is recognized.
Signature Details
function()
Encapsulates a method that has no parameters and does not return a value.Parameters
Returns
- ↪KeyboardInputModeBinding
- A token for the newly created command binding that can be used to later remove this binding from this instance again.
Examples
// Execute the command if the Insert key is pressed
graphEditorInputMode.keyboardInputMode.addKeyBinding(
'Insert',
ModifierKeys.NONE,
() => {
graphEditorInputMode.createNode(
graphEditorInputMode.graphComponent!.viewport.center,
)
},
)
See Also
addRecognizerBinding
(recognizer: function(EventArgs, unknown):boolean, action: function():void) : KeyboardInputModeBindingAdds a given action
to this instance that will be triggered if the given event recognizer recognizes a key event that has been triggered by the canvasComponent.
Parameters
A map of options to pass to the method.
- recognizer - function(EventArgs, unknown):boolean
- An event recognizer that will be fed with all key events.
Signature Details
function(evt: EventArgs, eventSource: unknown) : boolean
A callback that recognizes events.Given a sender and an event argument, delegates decide whether the event is treated as a match depending on the context.Parameters
- evt - EventArgs
- The arguments of the event to be decided to handle.
- eventSource - unknown
- The source of the event.
Returns
- boolean
true
if theevt
is considered to be handled.
- action - function():void
- The action to invoke if the recognizer matches an event.
Signature Details
function()
Encapsulates a method that has no parameters and does not return a value.Parameters
Returns
- ↪KeyboardInputModeBinding
- A token for the newly created command binding that can be used to later remove this binding from this instance again.
See Also
Will be called to unconditionally cancel all ongoing edits.
Remarks
This will be called prior to the uninstalling of this instance and when other input modes temporarily acquire the mutex.
In order to stop an active input mode manually, client code should use the following idiom:
if (!mode.tryStop()) {
mode.cancel()
}
Implements
Installs this mode into the given context that is provided by the canvas.
Remarks
In general a mode can only be installed into a single canvas at all times.
This method is called to initialize this instance. Subclasses should override this method to register the corresponding event handler delegates for the various input events they need to register with.
Overriding implementations should call the base implementation first.
Parameters
A map of options to pass to the method.
- context - IInputModeContext
- The context that this instance shall be installed into. The same instance will be passed to this instance during uninstall. A reference to the context may be kept and queried during the time the mode is installed.
- controller - ConcurrencyController
- The controller for this mode.
See Also
Implements
Called after cancel has been called.
Remarks
Can be overridden in subclasses to perform additional actions after the mode has been canceled.
This implementation does nothing.
Called after the active property of the installed ConcurrencyController has been set to true
.
Remarks
Enables the registered commands and can be overridden in subclasses to perform additional actions after the mode has been activated.
Overriding implementations should call the base implementation.
Called after the active property of the installed ConcurrencyController has been set to false
.
Remarks
Disables the registered commands and can be overridden in subclasses to perform additional actions after the mode has been deactivated.
Overriding implementations should call the base implementation.
Called after tryStop has been called.
Remarks
Can be overridden in subclasses to perform additional actions after the mode has been stopped.
This implementation does nothing.
Triggers the text-input event.
Parameters
A map of options to pass to the method.
- evt - TextEventArgs
- The event arguments.
Overridden to only return true
if this instance does not currently have the input mutex.
Uninstalls this mode from the given context.
Remarks
This code should clean up all changes made to the canvas in the install method. After a mode has been uninstalled it can be installed again into the same or another canvas.
Overriding implementations should call the base implementation after their own code.
Parameters
A map of options to pass to the method.
- context - IInputModeContext
- The context to deregister from. This is the same instance that had been passed to install during installation.
Implements
Events
Occurs when text was input, but the event was not handled or did not match a command.