简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM