How to catch mouse/keyboard event in Office addin

  • Thread starter Thread starter Frank King
  • Start date Start date
F

Frank King

Hi,

I am writing Office COM addin. I need to catch mouse/
keyboard events, such as mouse click, key press inside
the addin. Could somebody tell me some information
about it?

Thank you very much.

fk
 
When working with forms, each of the different objects including ActiveX
objects has the different Events. To look up the events, right click on the
Object, then click on Properties
Now click on "Event" tab.

It's in there where you have MouseDown, MouseMove, MouseUp, KeyDown,
KeyPress, and KeyUp events, if available, which should be in a good majority
of the cases. Now click on one of those events, click on the "..." to the
right of it, then click on "Code"

If you have created your own objects, you will also have to create the
events for that object in a class module of the object that deals with using
the WithEvents command, something I still have yet to learn more about.
 
Thank you very much for the message.

In fact, I am not using form. Instead, I am trying to
catch the mouse click or keyboard press in choosing the
menu I added with COM addin, say in EXCEL. After a user
clicks mouse button or presses the keyboard to choose a
menu (from top to the target menu), I try to start some
work, such as thread, before starting to run the function
for the target menu. For that reason, I am looking for
some methods to catch the mouse and keyboard event.

Do you have an idea about how to so?

Regards.

fk
 
This sounds like you are trying to do some things with regards to the
CommandBars collection and CommandBar object. I haven't worked with that
object too much in particular, but that is basically the collection and
object you are attempting to capture the keystrokes with. I would at this
point suggest start looking in the help files and online in that particular
part of the help files.
 
After looking into it, you may want to take a look at the following code:

Take a look at the OnAction property of a CommandButton

Example:

Application.CommandBars("Worksheet Menu
Bar").Controls("&Edit").Controls("Can't &Undo").OnAction =
<StringNameOfMacro>

This is how you would set the name of the macro to the Click Event of the
button such as this would set some macro to the "Can't &Undo" button that's
on the "&Edit" menu, which is on the main Excel menu toolbar.
 
Back
Top