Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2007

Tip: Looking for answers? Try searching our database.

Word 2007 key bindings - VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
olley - 04 Sep 2007 21:48 GMT
Hi,

I have problem with KeyBindings in Word 2007. I bind diferrent funcitons to
Alt+8 and Alt+* (on numeric pad). It works just fine in Word 2003. However in
Word 2007 it always calls Alt+8 bound function. Seems that Word 2007 cannot
differentiate between wdKey8 and wdKeyNumericMultiply, even though
BuildKeyCode() returns different values for those combinations.

Does anyone know if this is a bug or a feature in new Word 2007? Is there a
workaround for this?

Thanks!

Here is the code sample. In Word 2007 it always call "EghtPressed"

KeyBindings.Add KeyCode:=BuildKeyCode(
 arg1:=wdKeyAlt,
 Arg2:=wdKey8),
 KeyCategory:=wdKeyCategoryCommand,
 Command:="EightPressed"
       
KeyBindings.Add KeyCode:=BuildKeyCode(
 arg1:=wdKeyAlt,  
 Arg2:=wdKeyNumericMultiply),
 KeyCategory:=wdKeyCategoryCommand,
 Command:="StarPressed"
Klaus Linke - 05 Sep 2007 01:58 GMT
Haven't checked it out in Word 2007, but using the Windows API should do the
trick.
See Romke Soldaat's article
http://msdn2.microsoft.com/en-us/library/Aa155749(office.10).aspx
(scroll down to "The Keybinding Mess" and "Get the API to Do the Work VBA
Can't Do")

Regards,
Klaus

> Hi,
>
[quoted text clipped - 26 lines]
>  KeyCategory:=wdKeyCategoryCommand,
>  Command:="StarPressed"
olley - 07 Sep 2007 21:52 GMT
Hi Klaus,

Thanks for your response.

> Haven't checked it out in Word 2007, but using the Windows API should do the
> trick.
> See Romke Soldaat's article
> http://msdn2.microsoft.com/en-us/library/Aa155749(office.10).aspx
> (scroll down to "The Keybinding Mess" and "Get the API to Do the Work VBA
> Can't Do")

Unfortunately it didn't do the trick ;) This article (that particular part
you pointed to) explains how to get correct scancode for any keyboard using
VkKeyScan() Win API function. However, in MSDN for this function they say:
"Translations for the numeric keypad (VK_NUMPAD0 through VK_DIVIDE) are
ignored." And indeed it doesn't build scancode for * on numeric keyboard.

The problem here is not getting correct scancode, but rather is how Word
2007 binds keys on numeric keypad (even for well-known scan codes). To me it
seems that Word 2007 cannot handle numeric keypad key bindings correctly.

Thank you,
Klaus Linke - 08 Sep 2007 19:09 GMT
Yes, seems like it's reserved or something. I can assign
wdKeyNumericMultiply alone, but not with Alt.
Maybe it has something to do with ribbon navigation (using Alt, and then
moving through the tabs and chunks with the direction keys)?

I can assign Alt+wdKeyNumeric8, though it only works if NumLock is turned
on.

Regards,
Klaus

> Hi Klaus,
>
[quoted text clipped - 21 lines]
>
> Thank you,
olley - 13 Sep 2007 20:02 GMT
> Yes, seems like it's reserved or something. I can assign
> wdKeyNumericMultiply alone, but not with Alt.
> Maybe it has something to do with ribbon navigation (using Alt, and then
> moving through the tabs and chunks with the direction keys)?

I ended up doing following. I bind "8" key with Alt using regular call:
KeyBindings.Add
  KeyCode:=BuildKeyCode(arg1:=wdKeyAlt, arg2:=wdKey8),
  KeyCategory:=wdKeyCategoryCommand,
  Command:="Handler8"

And then in Handler8() funciton I check if wdKeyNumericMultiply is still
pressed. For that I use Win32 API GetKeyState() function. If it is pressed
then I call my regular handler for Alt+<Num*> keystroke. There is a potential
danger that by the time I call GetKeyState() the user would already release
Num*. But it seems to be working for me now. Oh, and I do it only if the
current Word version is 2007.

Klaus, thanks for the idea of using Win32 API directly. I would not get to
it without your hint about different API call ;)
Klaus Linke - 15 Sep 2007 01:35 GMT
Thanks, and good to hear you got something working!

Regards,
Klaus
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.