1: //#if WFA
2: using System;
3: using System.Drawing;
4: using System.Threading;
5: using System.Windows.Forms;
6:
7: namespace Ia.Cl.Model
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: public Mouse() { }
28:
29: ////////////////////////////////////////////////////////////////////////////
30:
31: /// <summary>
32: ///
33: /// </summary>
34: public static Point Position()
35: {
36: return Cursor.Position;
37: }
38:
39: ////////////////////////////////////////////////////////////////////////////
40:
41: /// <summary>
42: ///
43: /// </summary>
44: public static void Position(out int x, out int y)
45: {
46: x = Cursor.Position.X;
47: y = Cursor.Position.Y;
48: }
49:
50: ////////////////////////////////////////////////////////////////////////////
51:
52: /// <summary>
53: ///
54: /// </summary>
55: public static void Position(int x, int y)
56: {
57: Cursor.Position = new Point(x, y);
58: }
59:
60: ////////////////////////////////////////////////////////////////////////////
61:
62: /// <summary>
63: ///
64: /// </summary>
65: public static void Move(Point p)
66: {
67: Move(p.X, p.Y);
68: }
69:
70: ////////////////////////////////////////////////////////////////////////////
71:
72: /// <summary>
73: ///
74: /// </summary>
75: public static void Move(int x, int y)
76: {
77: int x_orig, y_orig;
78: int x_path, y_path;
79: int step;
80:
81: x_orig = Cursor.Position.X;
82: y_orig = Cursor.Position.Y;
83:
84: step = (int)Math.Sqrt(Math.Pow(x - x_orig, 2) + Math.Pow(y - y_orig, 2));
85:
86: step /= 10;
87:
88: for (int i = 1; i <= step; i++)
89: {
90: x_path = x_orig + i * (x - x_orig) / step;
91: y_path = y_orig + i * (y - y_orig) / step;
92:
93: Cursor.Position = new Point(x_path, y_path);
94: Thread.Sleep(30);
95: }
96:
97: Cursor.Position = new Point(x, y);
98: }
99:
100: ////////////////////////////////////////////////////////////////////////////
101:
102: /// <summary>
103: ///
104: /// </summary>
105: public static void Wait(int millisecond)
106: {
107: Thread.Sleep(millisecond);
108: }
109:
110: ////////////////////////////////////////////////////////////////////////////
111:
112: /// <summary>
113: ///
114: /// </summary>
115: public static void ClickLeftSingle()
116: {
117: Ia.Cl.Model.Winapi.SendLeftClick();
118: }
119:
120: ////////////////////////////////////////////////////////////////////////////
121:
122: /// <summary>
123: ///
124: /// </summary>
125: public static void ClickLeftDouble()
126: {
127: Ia.Cl.Model.Winapi.SendLeftClick();
128: Thread.Sleep(100);
129: Ia.Cl.Model.Winapi.SendLeftClick();
130: }
131:
132: ////////////////////////////////////////////////////////////////////////////
133:
134: /// <summary>
135: ///
136: /// </summary>
137: public static void ClickLeftDragMouse(int x, int y)
138: {
139: Ia.Cl.Model.Winapi.SendLeftDownClick();
140: Move(x, y);
141: Ia.Cl.Model.Winapi.SendLeftUpClick();
142: }
143:
144: ////////////////////////////////////////////////////////////////////////////
145:
146: /// <summary>
147: ///
148: /// </summary>
149: public static void ClickRightSingle()
150: {
151: Ia.Cl.Model.Winapi.SendRightClick();
152: }
153:
154: ////////////////////////////////////////////////////////////////////////////
155:
156: /// <summary>
157: ///
158: /// </summary>
159: public static void ClickRightDouble()
160: {
161: Ia.Cl.Model.Winapi.SendRightClick();
162: Thread.Sleep(100);
163: Ia.Cl.Model.Winapi.SendRightClick();
164: }
165:
166: ////////////////////////////////////////////////////////////////////////////
167:
168: /// <summary>
169: ///
170: /// </summary>
171: public static void Key(string n)
172: {
173: // print string
174: // SendKeys.Send(n);
175: SendKeys.SendWait(n);
176: }
177:
178: ////////////////////////////////////////////////////////////////////////////
179: ////////////////////////////////////////////////////////////////////////////
180: }
181: }
182: //#endif