Skip to main content Skip to footer

Customizing Keyboard Actions

You may wish to change the default keyboard key actions in Spread Windows Forms to something that is easier to use or you may want to disable a default keyboard action and use it for some other action. You can customize the default keyboard actions in Spread by customizing the input map. An input map is essentially a collection of keystrokes and related actions. Spread provides a WhenFocused input map for processing keystrokes that occur while the component has focus. The WhenFocused input map is used to implement the FpSpread class IsInputKey, IsInputChar, OnKeyDown, OnKeyPress, and OnKeyUp methods which in turn raise the KeyDown, KeyPress, and KeyUp events. Spread provides a WhenAncestorOfFocused input map for processing keystrokes that occur while the component or one of its child controls has focus. The WhenAncestorOfFocused input map is used to implement the FpSpread class's ProcessDialogKey and ProcessDialogChar methods. These methods do not raise any events. Most keystrokes processed by the Spread component must be processed whether the component or one of its child controls have focus, which means that most of the Spread keyboard behavior is described in the WhenAncestorOfFocus input map. The Spread component has multiple operation modes (Normal, ReadOnly, RowMode, SingleSelect, MultiSelect, ExtendedSelect). Each operation mode requires different keyboard behavior, so the Spread component has separate WhenFocused and WhenAncestorOfFocused input maps for each operation mode. The predefined actions available for the Spread component and the available actions to which you can map keys or key combinations are in the SpreadActions class. If you want to turn off one of the default map keystroke settings, you can set the keystroke to the None member of the SpreadActions class. For more information about the programming interface for inputs, actions, and maps, refer to these classes:

  • Action class
  • ActionMap class
  • InputMap class
  • KeyStroke class
  • SpreadActions class
  • UndoAction class

For a typical Spread component, most interactions that occur while you are working with the component occur as part of the WhenAncestorOfFocused input map. Actions such as moving the active cell, selecting a range of cells, and others would be part of this map. For example, pressing the Tab key moves the active cell, even if a cell is in edit mode. In contrast, some keys are only mapped when there is not a cell in edit mode (the component has the focus, but not a cell editor). For example, the equals (=) key does not perform an action if pressed when a cell is in edit mode. If no cell is in edit mode, pressing the equals key starts formula editing for the active cell. Default map topics in the product documentation list default keys for the operation mode and input map mode. This example deactivates the F2 key.

C#

private void Form1_Load(object sender, System.EventArgs e){ FarPoint.Win.Spread.InputMap im = new FarPoint.Win.Spread.InputMap(); // Deactivate F2 key in cells not being edited. im = fpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenFocused); im.Put(new FarPoint.Win.Spread.Keystroke(Keys.F2, Keys.None), FarPoint.Win.Spread.SpreadActions.None); // Deactivate F2 key in cells being edited. im = fpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenAncestorOfFocused); im.Put(new FarPoint.Win.Spread.Keystroke(Keys.F2, Keys.None), FarPoint.Win.Spread.SpreadActions.None); }

VB

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.LoadDim im As New FarPoint.Win.Spread.InputMap ' Deactivate F2 key in cells not being edited. im = FpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenFocused) im.Put(New FarPoint.Win.Spread.Keystroke(Keys.F2, Keys.None), FarPoint.Win.Spread.SpreadActions.None) ' Deactivate F2 key in cells being edited. im = FpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenAncestorOfFocused) im.Put(New FarPoint.Win.Spread.Keystroke(Keys.F2, Keys.None), FarPoint.Win.Spread.SpreadActions.None) End Sub

This example changes the behavior so that pressing the Enter key moves the active cell to the next row for normal operation mode.

  1. Create a new InputMap object for which to map keys and actions.
  2. Set an existing input map equal to the InputMap object you created.
  3. Use the InputMap class Put method to map specific keys to specific actions.

C#

private void Form1_Load(object sender, System.EventArgs e) { FarPoint.Win.Spread.InputMap im = new FarPoint.Win.Spread.InputMap(); // Define the operation of pressing Enter key in cells not being edited as "Move to the next row". im = fpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenFocused); im.Put(new FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), FarPoint.Win.Spread.SpreadActions.MoveToNextRow); // Define the operation of pressing Enter key in cells being edited as "Move to the next row". im = fpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenAncestorOfFocused); im.Put(new FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), FarPoint.Win.Spread.SpreadActions.MoveToNextRow); }

VB

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim im As New FarPoint.Win.Spread.InputMap ' Define the operation of pressing Enter key in cells not being edited as "Move to the next row". im = FpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenFocused) im.Put(New FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), FarPoint.Win.Spread.SpreadActions.MoveToNextRow) ' Define the operation of pressing Enter key in cells being edited as "Move to the next row". im = FpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenAncestorOfFocused) im.Put(New FarPoint.Win.Spread.Keystroke(Keys.Enter, Keys.None), FarPoint.Win.Spread.SpreadActions.MoveToNextRow) End Sub

MESCIUS inc.

comments powered by Disqus