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

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