User input via the keyboard is handled by the IKeyHandlingService. For a class or view model to handle keyboard input in must implement IKeyHandlingSupported.
A new IKeyHandlingService must be created for each handling class and is created via IKeyHandlingServiceFactory:
// Create key handling service IKeyHandlingService keyHandlingService = keyHandlingServiceFactory.Create(this.InstanceIdentifier);
Registering Keyboard Input
Any key or key combination requiring handling will have to have its own IKeyInputCommandInfo creating:
internal sealed class NextPageInputCommandInfo : KeyInputCommandInfoBase { // Unique identifier for this key combination public static readonly InputCommandId = new Guid("14C0C59F-F3D0-4528-A899-3E02A229EF9B"); public NextPageInputCommandInfo() : base( InputCommandId.NextPageage, "Move to the next page", new[] { new KeyInputGesture(Key.PageDown) }) { } }
All IKeyInputCommandInfo classes will need registering in the IoC container. An easy way of doing this for all instances is to use the following code:
builder.RegisterTypes( typeof(PluginModule) .Assembly .GetTypes() .Where(t => t.GetInterfaces().Contains(typeof(IKeyInputCommandInfo))) .ToArray()) .As<IKeyInputCommandInfo>();
Handling Keyboard Input
Keyboard input should be handle by using the following code:
// Define the key handling logic method IKeyInputCommandInfo<object, KeyInputInfo> handler = this.HandleNextPage; // Register the handler with the unique identifier of the IKeyInputCommandInfo keyHandlingService.RegisterKeyInputHandler( NextPageInputCommandInfo.InputCommandId, handler);
Comments
0 comments
Please sign in to leave a comment.