473,320 Members | 1,865 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,320 software developers and data experts.

Can C# listen for system events?

I am trying to determine if C# has the capabilities to listen for system
events when the application does not have the window's focus.

I am writing a windows application that I would like to run in the
background when I am using my computer. I would like this windows
application to utilize the clipboard, and determine when data has changed on
the clipboard. I would also like my app to listen for Ctrl+C and Ctrl+V
events, as well as mouse copy/paste events.

What I have be able to explore so far is that I can write an app that will
listen for keyboard events when the application has window's focus. I cannot
seem to find any information on if it is possible to listen to events when
the window does not have focus.

Can anyone provide insight to help me out? Preferably C# code if it's
possible. Is this solution possible with the C# language?

Thanks,

Alex
Jul 19 '05 #1
2 14268
Hello Alex,

Thanks for your post. Generally speaking, we use Hooks to monitor the
message traffic in the system and process certain types of messages before
they reach the target window procedure. To listen for system wide message,
you should implement Global Hook. However, Microsoft .NET Framework does
not support Global Hook. That is, we are not able to use C# to implement
it, here is the reason:

"To install a global hook, a hook must have a native dynamic-link library
(DLL) export to inject itself in another process that requires a valid,
consistent function to call into. This requires a DLL export, which .NET
Framework does not support. Managed code has no concept of a consistent
value for a function pointer because these function pointers are proxies
that are built dynamically."

To work around this problem, we have to use Visual C++ to create native
Hook DLL. I believe the following MSDN articles are helpful:

HOW TO: Set a Windows Hook in Visual C# .NET
http://support.microsoft.com/?kbid=318804

SetWindowsHookEx
http://msdn.microsoft.com/library/de...us/winui/winui
/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindows
hookex.asp

Hooks
http://msdn.microsoft.com/library/de...us/winui/winui
/windowsuserinterface/windowing/hooks.asp?frame=true

Please feel free to let me know if you have any problems or concerns.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! ¨C www.microsoft.com/security
This posting is provided ¡°as is¡± with no warranties and confers no rights.

Jul 19 '05 #2
Hi Alex,

You can do this in C# but you have to use the Win32 API. The
SetClipboardViewer() function can be used to register your application for
notifications of clipboard changes.

I have an article and an example in C# on my site that goes into more
detail.

http://www.radsoftware.com.au/web/CodeZone

--
Ross Donald
http://www.radsoftware.com.au/web/WebLog/

"Alex" <ba*******@hotmail.com> wrote in message
news:uZ**************@TK2MSFTNGP09.phx.gbl...
I am trying to determine if C# has the capabilities to listen for system
events when the application does not have the window's focus.

I am writing a windows application that I would like to run in the
background when I am using my computer. I would like this windows
application to utilize the clipboard, and determine when data has changed on the clipboard. I would also like my app to listen for Ctrl+C and Ctrl+V
events, as well as mouse copy/paste events.

What I have be able to explore so far is that I can write an app that will
listen for keyboard events when the application has window's focus. I cannot seem to find any information on if it is possible to listen to events when
the window does not have focus.

Can anyone provide insight to help me out? Preferably C# code if it's
possible. Is this solution possible with the C# language?

Thanks,

Alex

Jul 19 '05 #3

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

Similar topics

1
by: Alex Stevens | last post by:
Hi All, I have a situation where I have two forms - FormA and FormB. FormA has a list of Customers which when you double-click open the selected customer. FormB displays that Customer. FormB...
0
by: Eric | last post by:
Hi, I wonder if it is possible to listen to events from other applications that you have not written yourself and that you don't know anything about? Notepad or any other windows application for...
5
by: Alex | last post by:
I am trying to determine if C# has the capabilities to listen for system events when the application does not have the window's focus. I am writing a windows application that I would like to run...
9
by: mBird | last post by:
I wrote a service that listens for broadcast messages from my firewall (UDP snmp trap messages) and parses and puts the data in an database. I'd also like to write an app that is a simple form...
4
by: Sean Connery | last post by:
I know I can merge a child forms menu into the MDI parent's mainmenu, but I would also like to listen for common events fired from the mainmenu that might be of interest to any child forms. Is...
5
by: Ted Shab | last post by:
Hi, I'm trying to come up with a relatively simple multi-master replication solution. This is for multiple databases that need to be discreet, and change relatively infrequently (10-30 updates...
4
by: bbembi_de | last post by:
Hello, I want to get an event every time the ip address of a network adapter changes. How can I do it with C# and .Net1.1? Alternatively all events of the Dhcp Source would do too....
0
by: Magnus O. | last post by:
Hi! Is it possible to listen to volume changes in windows vista? My multimedia keys on my laptop controls the windows volume mixer but there is no OSD. Is it possible to listen to changed volume...
7
by: silverburgh.meryl | last post by:
Hi, I read the following code which open a server socket for client request. However, i would like to know how can I change it so that i just listen for client requestfor 10 seconds, after...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.