Terry
Terry

Reputation: 11

How can I tell if the contextmenu item was clicked with the mouse or fired by a hotkey?

I have a DataGridView with a context menu. One menu item is Copy (with a Ctrl+C hotkey.) All I want to do is either get the current mouse location to copy the cell that the user right-clicked, or get the currently selected cell if they used the hot-key. In both cases the menu_Click event gets fired. How can I tell if it was from a hotkey or the context menu?

Upvotes: 0

Views: 125

Answers (1)

Furqan Safdar
Furqan Safdar

Reputation: 16698

To best of my knowledge you can Hook all the Mouse and Keyboard events to detect the source of input.

You should have a look at this CodeProject article, Processing Global Mouse and Keyboard Hooks in C#

MSDN Reference:

A global hook monitors messages for all threads in the same desktop as the calling thread. A thread-specific hook monitors messages for only an individual thread. A global hook procedure can be called in the context of any application in the same desktop as the calling thread, so the procedure must be in a separate DLL module. A thread-specific hook procedure is called only in the context of the associated thread.

Upvotes: 1

Related Questions