Reply
 
Thread Tools Display Modes
  #1   Report Post  
 
Posts: n/a
Default How to overwrite shortcut keys function in word

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.wdK eyCategoryCommand,
"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.

  #2   Report Post  
CyberTaz
 
Posts: n/a
Default

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 |:)

" wrote:

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.wdK eyCategoryCommand,
"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.


  #3   Report Post  
MatthewTap
 
Posts: n/a
Default

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]

" wrote:

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.wdK eyCategoryCommand,
"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.


  #4   Report Post  
Suzanne S. Barnhill
 
Posts: n/a
Default

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
Word MVP FAQ site: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

wrote in message
ps.com...
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.wdK eyCategoryCommand,
"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.


  #5   Report Post  
Tony Jollans
 
Posts: n/a
Default

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?)

--
Enjoy,
Tony


wrote in message
ps.com...
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.wdK eyCategoryCommand,
"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.



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Word2000 letterhead merge BAW Mailmerge 3 June 25th 05 01:17 PM
Making Word do something that Wordperfect can do NarniaUK New Users 4 May 1st 05 10:44 PM
How do I get my default new document to always be our company let. QuiltDiva Microsoft Word Help 5 April 1st 05 08:20 AM
WordPerfect keyboard macro>Word equivalent? Anty New Users 2 March 13th 05 06:23 PM
creating forms Fluffypink Microsoft Word Help 4 March 9th 05 04:17 PM


All times are GMT +1. The time now is 10:00 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"