Click here to Skip to main content
16,004,778 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to create an exe, when i run the exe it should perform some action on each mouse click and keyboard press events without triggering any other button click events.
C#
private void btn_Click(object sender, EventArgs e)
 {
 if (e.Button == System.Windows.Forms.MouseButtons.Right){MessageBox.Show("Right click");}
 if (e.Button == System.Windows.Forms.MouseButtons.Left){MessageBox.Show("Left click");}
 }

I googled it and i don't find my requirement. can anybody please help me.

Thanks in advance
Posted
Updated 2-Feb-16 0:25am
v2
Comments
Sinisa Hajnal 2-Feb-16 6:27am    
Google "global event hooks in windows"
Renjith_R 2-Feb-16 7:29am    
I have tried this. in global hooks events the mouse events and key press events are triggered based on the check box click events.
BillWoodruff 2-Feb-16 6:57am    
Do you mean when the user performs a MouseClick on some other Application's UI, with your Application not having focus ?
Renjith_R 2-Feb-16 7:26am    
Thanks for your reply, I need to capture an image on each mouse click and keyboard press events.
BillWoodruff 2-Feb-16 7:35am    
an "image" of what ? "image" implies bit-map / screen-shot. please answer the question about whether or not you are trying to get Events outside your running Application.

1 solution

I think you'll find a solution in this CodeProject article:
Processing Global Mouse and Keyboard Hooks in C#[^]

It's most up-to-date project can be found on GitHub:
gmamaladze/globalmousekeyhook - C# - GitHub[^]

I took a glance at it and it looks really easy and straight forward.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900