)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » Mouse (Ia.Cl.Models)

Public general use code classes and xml files that we've compiled and used over the years:

Windows mouse movements and properties control support class.

    1: //#if WFA
    2: using System;
    3: using System.Drawing;
    4: using System.Threading;
    5: using System.Windows.Forms;
    6:  
    7: namespace Ia.Cl.Models
    8: {
    9:     /// <summary publish="true">
   10:     /// Windows mouse movements and properties control support class.
   11:     /// </summary>
   12:     /// <remarks> 
   13:     /// Copyright � 2001-2015 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   14:     ///
   15:     /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
   16:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   17:     ///
   18:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   19:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   20:     /// 
   21:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   22:     /// 
   23:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   24:     /// </remarks>
   25:     public class Mouse
   26:     {
   27:         ////////////////////////////////////////////////////////////////////////////
   28:  
   29:         /// <summary>
   30:         ///
   31:         /// </summary>
   32:         public Mouse() { }
   33:  
   34:         ////////////////////////////////////////////////////////////////////////////
   35:  
   36:         /// <summary>
   37:         ///
   38:         /// </summary>
   39:         public static Point Position()
   40:         {
   41:             return Cursor.Position;
   42:         }
   43:  
   44:         ////////////////////////////////////////////////////////////////////////////
   45:  
   46:         /// <summary>
   47:         ///
   48:         /// </summary>
   49:         public static void Position(out int x, out int y)
   50:         {
   51:             x = Cursor.Position.X;
   52:             y = Cursor.Position.Y;
   53:         }
   54:  
   55:         ////////////////////////////////////////////////////////////////////////////
   56:  
   57:         /// <summary>
   58:         ///
   59:         /// </summary>
   60:         public static void Position(int x, int y)
   61:         {
   62:             Cursor.Position = new Point(x, y);
   63:         }
   64:  
   65:         ////////////////////////////////////////////////////////////////////////////
   66:  
   67:         /// <summary>
   68:         ///
   69:         /// </summary>
   70:         public static void Move(Point p)
   71:         {
   72:             Move(p.X, p.Y);
   73:         }
   74:  
   75:         ////////////////////////////////////////////////////////////////////////////
   76:  
   77:         /// <summary>
   78:         ///
   79:         /// </summary>
   80:         public static void Move(int x, int y)
   81:         {
   82:             int x_orig, y_orig;
   83:             int x_path, y_path;
   84:             int step;
   85:  
   86:             x_orig = Cursor.Position.X;
   87:             y_orig = Cursor.Position.Y;
   88:  
   89:             step = (int)Math.Sqrt(Math.Pow(x - x_orig, 2) + Math.Pow(y - y_orig, 2));
   90:  
   91:             step /= 10;
   92:  
   93:             for (int i = 1; i <= step; i++)
   94:             {
   95:                 x_path = x_orig + i * (x - x_orig) / step;
   96:                 y_path = y_orig + i * (y - y_orig) / step;
   97:  
   98:                 Cursor.Position = new Point(x_path, y_path);
   99:                 Thread.Sleep(30);
  100:             }
  101:  
  102:             Cursor.Position = new Point(x, y);
  103:         }
  104:  
  105:         ////////////////////////////////////////////////////////////////////////////
  106:  
  107:         /// <summary>
  108:         ///
  109:         /// </summary>
  110:         public static void Wait(int millisecond)
  111:         {
  112:             Thread.Sleep(millisecond);
  113:         }
  114:  
  115:         ////////////////////////////////////////////////////////////////////////////
  116:  
  117:         /// <summary>
  118:         ///
  119:         /// </summary>
  120:         public static void ClickLeftSingle()
  121:         {
  122:             Ia.Cl.Models.Winapi.SendLeftClick();
  123:         }
  124:  
  125:         ////////////////////////////////////////////////////////////////////////////
  126:  
  127:         /// <summary>
  128:         ///
  129:         /// </summary>
  130:         public static void ClickLeftDouble()
  131:         {
  132:             Ia.Cl.Models.Winapi.SendLeftClick();
  133:             Thread.Sleep(100);
  134:             Ia.Cl.Models.Winapi.SendLeftClick();
  135:         }
  136:  
  137:         ////////////////////////////////////////////////////////////////////////////
  138:  
  139:         /// <summary>
  140:         ///
  141:         /// </summary>
  142:         public static void ClickLeftDragMouse(int x, int y)
  143:         {
  144:             Ia.Cl.Models.Winapi.SendLeftDownClick();
  145:             Move(x, y);
  146:             Ia.Cl.Models.Winapi.SendLeftUpClick();
  147:         }
  148:  
  149:         ////////////////////////////////////////////////////////////////////////////
  150:  
  151:         /// <summary>
  152:         ///
  153:         /// </summary>
  154:         public static void ClickRightSingle()
  155:         {
  156:             Ia.Cl.Models.Winapi.SendRightClick();
  157:         }
  158:  
  159:         ////////////////////////////////////////////////////////////////////////////
  160:  
  161:         /// <summary>
  162:         ///
  163:         /// </summary>
  164:         public static void ClickRightDouble()
  165:         {
  166:             Ia.Cl.Models.Winapi.SendRightClick();
  167:             Thread.Sleep(100);
  168:             Ia.Cl.Models.Winapi.SendRightClick();
  169:         }
  170:  
  171:         ////////////////////////////////////////////////////////////////////////////
  172:  
  173:         /// <summary>
  174:         ///
  175:         /// </summary>
  176:         public static void Key(string n)
  177:         {
  178:             // print string
  179:             // SendKeys.Send(n);
  180:             SendKeys.SendWait(n);
  181:         }
  182:  
  183:         ////////////////////////////////////////////////////////////////////////////
  184:         ////////////////////////////////////////////////////////////////////////////
  185:     }
  186: }
  187: //#endif