473,401 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

C# - Detect Mouse Click Outside Form

There's another topic like this but the code posted is in VB.NET.

Well I need some help detecting mouse clicks outside the form. An event
handler would be great but I can work with anything.

Thanks in advance,

Alex

Jun 3 '06 #1
3 28527
You can utilize windows hooks in order to detect all mouse clicks...

http://www.codeproject.com/csharp/globalhook.asp
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com

<ak*****@gmail.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
There's another topic like this but the code posted is in VB.NET.

Well I need some help detecting mouse clicks outside the form. An event
handler would be great but I can work with anything.

Thanks in advance,

Alex

Jun 3 '06 #2
His code was written in VS 2003 and I'm using VS 2005. I implemented
his code into my project and it threw an exception...

System.Exception was unhandled
Message="SetWindowsHookEx failed."
Source="rsmm"
StackTrace:
at GlobalHookDemo.UserActivityHook.Start() in C:\Documents and
Settings\Administrator\My Documents\Visual Studio
2005\Projects\rsmm\rsmm\UserActivityHook.cs:line 123
at GlobalHookDemo.UserActivityHook..ctor() in C:\Documents and
Settings\Administrator\My Documents\Visual Studio
2005\Projects\rsmm\rsmm\UserActivityHook.cs:line 29
at rsmm.Form1.Form1_Load(Object sender, EventArgs e) in
C:\Documents and Settings\Administrator\My Documents\Visual Studio
2005\Projects\rsmm\rsmm\Form1.cs:line 21
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean
fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallba ck(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow( HandleRef
hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolea n value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.Run MessageLoop(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at rsmm.Program.Main() in C:\Documents and
Settings\Administrator\My Documents\Visual Studio
2005\Projects\rsmm\rsmm\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.Run UsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context( Object
state)
at System.Threading.ExecutionContext.Run(ExecutionCon text
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

If anybody could help I really need it. :)

Jun 4 '06 #3
For the sake of other people that have the same as me I'll post this:

This is how to get the above code working under VS 2005:

(this is from the comments of the codeproject post)

You just need to UNCHECK the check box in the project properties that
says:
"Enable visual studio hosting process"

In the menu:

Project -> Project properties... -> Debug -> Enable the visual studio
hosting process

Jun 4 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: selowan | last post by:
Hi, In VB6 Pro SP5, I have a form that contains an MSFlexGrid and a few other textboxes and comboboxes. I am using the technique from MSDN article Q241355, which describes how to tab and edit in...
2
by: Pete Mann | last post by:
Hi Could anyone tell me if there is a command which will recongnise a simple mouse click anywhere on the screen, I can do it ok for a command box etc etc but would like to be able to simply click...
6
by: lauren quantrell | last post by:
I have a command button on a continuous subform and I want the user to click it to open a small popup form that opens in the position of the mouse (which is the same as the position of the command...
8
by: NeoAsimov | last post by:
Hello, There is what I want to do. I worked on the problem since 6 hours but I had a problem (probably stupid) and I dont know how to resolve it. I need to have an Mouse Event Click when...
4
by: Harry J. Smith | last post by:
How can you detect a mouse double click on a text box? I tried the following but it does not work. private void richTextOut_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) //...
2
by: Sławomir Speth | last post by:
hi all How trap mouse click outside my control - like close popup menu
3
by: Iosy | last post by:
Hi all, I'm working in a application where I need to detect when the mouse is inactive outside my form. I mean, I want to detect if the mouse hasn't move in the last X seconds (2 por example)...
18
by: eliss.carmine | last post by:
Is it possible to simulate a mouse click in the window I made (it's a Form), but not give it focus? I tried using WinAPI's mouseevent and SendMessage of WM_LBUTTONDOWN/WM_LBUTTONUP as suggested...
10
by: bern11 | last post by:
If Form1 opens Form2 modally, how do I capture clicks on Form1 when Form2 is open? I want to click on Form1 and read the mouse co-ordinates into Form2. Since Form2 is open modally, Form1...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.