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