Keybinding and commandlinks

SyntaxEditor for Windows Forms Forum

Posted 20 years ago by Ajay
Avatar
My custom command action is not firing for the space key. It does work ok for the enter key. I am using the latest version 3. Any suggestions ?

'Enter - This works OK
kams = Me.editor.CommandLinks.GetApplicableCommandLinks(Keys.Enter)
If Not kams Is Nothing AndAlso kams.Length > 0 Then
Me.editor.CommandLinks.Remove(kams(0))
End If
kam = New ActiproSoftware.WinUICore.Commands.CommandLink(New EnterKeyAction, _
New ActiproSoftware.WinUICore.Commands.KeyBinding(Input.ModifierKeys.None, Keys.Enter))
Me.editor.CommandLinks.Add(kam)

' SPACE - This does NOT work
kams = Me.editor.CommandLinks.GetApplicableCommandLinks(Keys.Space)
If Not kams Is Nothing AndAlso kams.Length > 0 Then
Me.editor.CommandLinks.Remove(kams(0))
End If
kam = New ActiproSoftware.WinUICore.Commands.CommandLink(New SpaceKeyAction, _
New ActiproSoftware.WinUICore.Commands.KeyBinding(Input.ModifierKeys.None, Keys.Space))
Me.editor.CommandLinks.Add(kam)

The SpaceKeyAction class is defined as follows (The execute function is not getting called when I type
in space in the editor.) :
Public Class SpaceKeyAction
Inherits ActiproSoftware.SyntaxEditor.Commands.EditCommand

Public Overloads Overrides Sub Execute(ByVal context As ActiproSoftware.SyntaxEditor.Commands.EditCommandContext)
context.View.InsertText(" ")
Dim offset As Integer = context.SyntaxEditor.SelectedView.Selection.EndOffset
....

Comments (1)

Posted 20 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
.NET may consider space as a character key and not a control-based key, so command links probably won't work for it by default unless you added a modifier key to it (like Ctrl or Alt).

However, using our new key processing model in 3.0, you can wire it up a different way. In the KeyTyping event, look for a space and if you find it you can set the event arg's Command property to an instance of your custom command. Then your command will be executed instead of the default typing command.


Actipro Software Support

The latest build of this product (v24.1.1) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.