adspace
Hello,
I want to connect a system in LAN and i want to access
that.When ever i am moving a mouse in my desktop the
similar thing have to happend in the another system in
which i have connected.
I need coding for this in c# and .NET .
any one please help me.It is very urgent to me
Advance thanks.
my email id:manojkumarchallagundla@gmail.com
Answer Posted / Banafsha Siddiqui
For real-time mouse movement synchronization between two systems in LAN using C#, you can use WCF (Windows Communication Foundation) with callback mechanism. Here's a simple example:
1. Install the 'Service Library' and 'NetFX 4.0 Client Profile' project templates from Visual Studio.
2. Create a WCF service project containing the code for getting mouse position:
```csharp
using System;
using System.ServiceModel;
using System.Runtime.Serialization;
using System.Windows.Forms;
[ServiceContract]
public interface IMouseService
{
[OperationContract]
void UpdateMousePosition(int x, int y);
}
[DataContract]
public class MousePosition
{
[DataMember]
public int X { get; set; }
[DataMember]
public int Y { get; set; }
}
public class MouseService : IMouseService
{
public void UpdateMousePosition(int x, int y)
{
var client = OperationContext.Current.GetCallbackChannel<IMouseService>() as IMouseService;
if (client != null)
client.UpdateMousePosition(x, y);
}
}
```
3. Create a WCF client application that listens for the mouse movement event and calls the service when triggered:
```csharp
using System;
using System.ServiceModel;
using System.Windows.Forms;
namespace MouseClient
{
class Program
{
static void Main()
{
var client = new DuplexClient<IMouseService>("net.tcp://localhost/MouseService");
Application.AddMessageFilter(new MouseEventFilter(client));
Application.Run();
}
}
}
class MouseEventFilter : IMessageFilter
{
private readonly Action<int, int> _updateCallback;
public MouseEventFilter(Action<int, int> updateCallback)
{
_updateCallback = updateCallback;
}
public bool PreFilterMessage(ref Message message)
{
if (message.Label == "MouseUp" || message.Label == "MouseMove")
{
var args = (MouseEventArgs)message.Properties["APS_EventArg"];
_updateCallback(args.X, args.Y);
return true;
}
return false;
}
}
}
```
4. Register the service with net.tcp binding and host it in IIS.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers