Not handle Escape keyDown

Hello,

We’d like to use escape keydown event to close our project, and come back to our main application page.

But if the diagram has the focus, he handles the event…

I first try to override CommandHandler.CanStop (let it returns always false), but it is not the right solution : in this case, tools not be able to cancel the current action, but diagram still handle the keydown event.

The issue is to let current transaction be cancelled if needed, but if nothing is currently in use (no selection, no drag/drop, no move…) I’d like the diagram let the event for my environment.

Should I override each possible tool keydown ? Or exists a more central solution ?

Thanks
Aurore

You have the right idea. But you do want to “stop” sometimes, so you need to customize the StopCommand method. Here’s its standard definition:

public class CustomCommandHandler : CommandHandler { public override void StopCommand() { Diagram diagram = this.Diagram; if (diagram == null) return; IDiagramTool tool = diagram.CurrentTool; if (tool is ToolManager && diagram.AllowSelect) { diagram.ClearSelection(); } if (tool != null) { tool.DoCancel(); } } }
You might want to do something like:

public class CustomCommandHandler : CommandHandler { public override void StopCommand() { Diagram diagram = this.Diagram; if (diagram == null) return; IDiagramTool tool = diagram.CurrentTool; if (tool is ToolManager) { ... close project ... } else if (tool != null) { tool.DoCancel(); } } }