How to overwrite shortcut keys function in word

J

jayrm100

Hi,

We are in the process of building VSTO 2005 customizations for MS Word
2003.

One of our requirement is to overwrite short cut keys function in word.

Say for example, when a user presses ctrl+X keys the selected text
should not be cut, that is the default function of ctrl+X should not be
fired. Instead my function (Managed code and not a Macro) should be
executed.

We tried with Application.KeyBindings.Add but got the following error:
Word cannot change the function of the specified key.

Code:

this.Application.KeyBindings.Add(WdKeyCategory.wdKeyCategoryCommand,
"MenuItemNew1_Click", ThisApplication.BuildKeyCode(WdKey.wdKeyControl,
ref objKeyX, ref missing, ref missing), ref missing, ref missing);

Where MenuItemNew1_Click is a userdefined function.

Any pointers in resolving the same will be appreciated.

Thanks.
 
G

Guest

Hi Jay-

I don't claim to be aprogrammer, but on the basis of the example you gave
(Ctrl+X), you may be looking to the wrong culprit. Many kybd shortcuts are
_Windows_ based and merely supported within the applications. If you need to
override them it may have to be done at the OS level.

Regards |:>)
 
G

Guest

I was able to ovewrite ctrl-x by using it in a macro for word... not sure if
that's what you want to know or not.

Other than that, I was only able to find a list of shortcuts by going to
Windows Help and searching on "Keyboard shortcuts"....

[I brought the ctrl-x back to being 'cut' by deleting the macro]
 
S

Suzanne S. Barnhill

Not sure how this would work in managed code, but the technique in VBA is
not to reassign the shortcut but to hijack the command. That is, if you
write a macro named EditCut, then this will be performed when you press
Ctrl+X instead of Word's built in Cut command.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
T

Tony Jollans

It is possible to set a KeyBinding to Ctrl+x. All that the message really
means is that it can't (at the moment) bind it to the command you're trying
to use.

The most likely reason is that it can't find - or can't bind to - the
command.

If MenuItemNew1_Click is already bound to an ActiveX CommandButton you can't
bind to it. However, if you KeyBind to it before creating the button the
keybinding will stick - I don't know if that's an option for you. If it's in
a UserForm I'm not sure you can do it at all.

Don't know how any of this works with VSTO, I'm afraid - nor any of the C#
references (why objKeyX instead of wdKeyX for example? - and what is the
diference between This.Application and ThisApplication?)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top