Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
Available now!
Buy at Amazon US or
Buy at Amazon UK



Articles

1.Windows API reference
2.HTML to WML Converter
3.Webcam streaming in VB.NET
4.Remoting with firewalls
5.RSA from first principles
6.Key & MouseLogger in .NET
7.Networking Resource Kit for .NET
8.Automatic Reboot with .NET
9.XAML Schema
10.Migrating VB6 Winsock to VB.NET
11.Migrating C++ sockets to C#
12.RFC Reference guide
13.Lingua - Localization webservice
14.COM Reference guide
15.WMI Reference guide
16.SQL stored procedures
17.TCP & UDP port reference
18..NET Framework reference
19.Ethernet Type codes
21.MAC address assignments
22.DLL entry point reference
23.WHOIS server list
24. Turing Numbers
25. Boost SQL performance
26. Progress Bar in ASP.NET
27. OleDb WebService
27. Internet Explorer

Contact us


// Check for Mouse Move Events                       
if (lastX!=Control.MousePosition.X ||
lastY!=Control.MousePosition.Y)
{
lastX = Control.MousePosition.X;
lastY = Control.MousePosition.Y;
      MouseMoveEventArgs mouseMoveInfo = new
      MouseMoveEventArgs(lastX,lastY);
      if (OnMouseMove!=null)
      {
            OnMouseMove(this,mouseMoveInfo);
      }

}

Once we’ve got Mouse movement out of the way, let’s move on to mouse buttons. This is done in much the same way, first we have our EventArgs object (With an enumerated type to help tell what the user is doing to the button)–


public enum MouseButtonState {Pressed,Released}
public class MouseButtonEventArgs : EventArgs
{
public MouseButtonEventArgs(MouseButtons 
 Button,MouseButtonState buttonState)
      {
            this.Button = Button;
            this.buttonState = buttonState;
      }
      public readonly MouseButtons Button;
      public readonly MouseButtonState buttonState;

}

Then we add our delegate, event, and any state variables required –

private MouseButtons lastButton = MouseButtons.None;
public delegate void MouseButtonHandler
(object inputListener,
      MouseButtonEventArgs mouseButtonInfo);

public event MouseButtonHandler OnMouseButton;

Then the implementation of the polling mechanism


if (lastButton!=Control.MouseButtons)
{                      
MouseButtonEventArgs mouseButtonInfo;
      if (Control.MouseButtons==MouseButtons.None)
      {
            mouseButtonInfo = new
MouseButtonEventArgs(
lastButton, MouseButtonState.Released);
            if (OnMouseButton!=null)
{
OnMouseButton( this,
 mouseButtonInfo);
            }
      }                                        
      else
      {
            mouseButtonInfo = new
MouseButtonEventArgs(              
Control.MouseButtons,
MouseButtonState.Pressed);
            if (OnMouseButton!=null)
      {
      OnMouseButton( this,
mouseButtonInfo);
            }                                  
      }
      lastButton=Control.MouseButtons;         
}

Finally, we move on to key press detection. Once again, we define our EventArgs variable


public class KeyPressEventArgs : EventArgs
{
public KeyPressEventArgs( Keys ModifierKeys,
 int KeyCode)
      {
            this.ModifierKeys= ModifierKeys;
            this.KeyCode = KeyCode;
      }
      public readonly Keys ModifierKeys;
      public readonly int KeyCode;

}

We must declare our Event and Delegate as in the other two cases, however, in this instance, instead of using state variables, we declare our Win32 API call.

Page 1  Page 3 




Google

Copyright 2012 Open Merchant Account Ltd.
Free SMS UK Free SMS Ireland SMS Gratis Norway SMS Gratis Sverige Ilmainen SMS Suomi SMS Gratis Danmark SMS Tasuta Eestisse SMS Nemokamai Lietuva SMS Bezmaksas Latviju Darmowe smsy Polska SMS Zdarma Ceské SMS Zdarma Slovensko SMS Gratis Deutschland SMS Gratis Schweiz SMS Gratis Österreich SMS Gratuit Belgique SMS Gratis Nederland SMS Gratuit France SMS Gratis España SMS Gratis Portugal Free SMS South Africa Free SMS USA SMS Percuma Malaysia Free SMS Hong Kong