Posted 19 years ago by BTAC Developer
Avatar
I'm trying to use KeyTyping to capture when the user hits the K key while holding the Ctrl key ..how can this be done? I've experimented with the CommandLinks and it doesn't do anything...

Comments (8)

Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
KeyTyping's event args have a KeyData property. That has Ctrl+K specified when you press that combination.

If you are trying to tie an EditCommand to Ctrl+K, then add something like this to the CommandLinks:
editor.CommandLinks.Add(new CommandLink(new YourCommand(), new KeyBinding(WinUICore.Input.ModifierKeys.Control, Keys.K)));


Actipro Software Support

Posted 19 years ago by BTAC Developer
Avatar
I've tried that. It didn't work. How do I capture a command registered in the CommandLinks? I've tried the Command property from the KeyTyping event args and got nothing.
Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Yes it works fine. I just tied Ctrl+K to a Move Down command with this code added at the end of the sample project's MainForm constructor.
editor.CommandLinks.Add(new ActiproSoftware.WinUICore.Commands.CommandLink(new MoveDownCommand(), 
    new ActiproSoftware.WinUICore.Commands.KeyBinding(ActiproSoftware.WinUICore.Input.ModifierKeys.Control, Keys.K)));
The Command property from KeyTyping indicates what Command, if any, will execute by the key press you've made. It uses the CommandLinks to populate that.


Actipro Software Support

Posted 19 years ago by BTAC Developer
Avatar
Alright. I'm still a bit confused. I want to capture Ctrl+K in KeyTyping and handle it. What command would I want to pass inplace of MoveDownCommand() to accomplish that? Just a typing command? But then how do I 'catch' that in KeyTyping?

[Modified at 08/06/2005 04:51 PM]

[Modified at 08/06/2005 04:51 PM]
Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
EditCommands allow you to easily encapsulate some code that should occur when you press a hotkey. You can make your own and tie it up like I did. In that case you implement the Execute method of the EditCommand to do your code.

Alternatively, don't use EditCommands at all and just look for Ctrl+K in the KeyData prop of the KeyTyping event args and put your code in that event.

You can use whichever way you prefer.


Actipro Software Support

Posted 19 years ago by BTAC Developer
Avatar
I'm sorry, but that just doesn't make any sense to me. I don't understand how the EditCommands things works.


I have tried to handle the Ctrl+K in the KeyData property of KeyTyping and it doesn't work.

if ( KeyData == Keys.Control ) okay, so I can get one key, but I can't get the Other. That doesn't work. I don't understand how to execute an EditCommand at all.
Posted 19 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
The simpler of the two methods above to implement is the KeyTyping event. You have to check like this:
if (e.KeyData == (Keys.Control | Keys.K)) {
   // Do something
}


Actipro Software Support

Posted 19 years ago by BTAC Developer
Avatar
Of course, a Bitwise Operator. I never think to use those for anything. That works fine. Thanks.
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.