Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SendKeys.cs « System.Windows.Forms « Managed.Windows.Forms « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1b8837b32f9c0487233b4ac6d456a7dd7695912c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
//
// Authors:
//	Peter Bartok	(pbartok@novell.com)
//
//

// NOT COMPLETE

using System.Collections;

namespace System.Windows.Forms {
	public class SendKeys {
		#region Local variables
		private static Queue	keys = new Queue();
		#endregion

		#region Private methods
		private SendKeys() {
		}

		private static IntPtr CharToVKey(char key) {
			// FIXME - build a table to translate between vkeys and chars
			throw new NotImplementedException();
		}

		private static IntPtr SymbolToVKey(string symbol) {
			// FIXME - build a table to translate between vkeys and symbols
			throw new NotImplementedException();
		}

		private static void SendSymbol(IntPtr hwnd, string symbol, int repeat_count, bool down) {
			MSG	msg;

			if (down) {
				for (int i = 0; i < repeat_count; i++ ) {
					msg = new MSG();
					msg.hwnd = hwnd;
					msg.message = Msg.WM_KEYDOWN;
					msg.wParam = SymbolToVKey(symbol);
					msg.lParam = IntPtr.Zero;

					keys.Enqueue(msg);
				}
			} else {
				msg = new MSG();
				msg.hwnd = hwnd;
				msg.message = Msg.WM_KEYUP;
				msg.wParam = SymbolToVKey(symbol);
				msg.lParam = IntPtr.Zero;

				keys.Enqueue(msg);
			}
		}

		private static void SendKey(IntPtr hwnd, char key, int repeat_count) {
			MSG	msg;

			for (int i = 0; i < repeat_count; i++ ) {
				msg = new MSG();
				msg.hwnd = hwnd;
				msg.message = Msg.WM_KEYDOWN;
				msg.wParam = CharToVKey(key);
				msg.lParam = IntPtr.Zero;

				keys.Enqueue(msg);
			}

			msg = new MSG();
			msg.hwnd = hwnd;
			msg.message = Msg.WM_KEYUP;
			msg.wParam = CharToVKey(key);
			msg.lParam = IntPtr.Zero;

			keys.Enqueue(msg);
		}

		#endregion	// Private Methods

		#region Public Static Methods
		public static void Flush() {
			MSG msg;

			// FIXME - we only send to our own app, instead of the active app
			while (keys.Count > 0) {
				msg = (MSG)keys.Dequeue();
				XplatUI.TranslateMessage (ref msg);
				XplatUI.DispatchMessage (ref msg);
			}
		}

		[MonoTODO("Finish")]
		public static void Send(string key_string) {
			IntPtr	hwnd;
			int	shift_reset;
			int	control_reset;
			int	alt_reset;

			hwnd = XplatUI.GetActive();

			shift_reset = 0;
			control_reset = 0;
			alt_reset = 0;

			for (int i = 0; i < key_string.Length; i++) {
				switch(key_string[i]) {
					case '+': {
						SendSymbol(hwnd, "SHIFT", 1, true);
						shift_reset = 2;
						break;
					}

					case '^': {
						SendSymbol(hwnd, "CONTROL", 1, true);
						control_reset = 2;
						break;
					}

					case '%': {
						SendSymbol(hwnd, "ALT", 1, true);
						alt_reset = 2;
						break;
					}

					case '~': {
						SendSymbol(hwnd, "ENTER", 1, true);
						SendSymbol(hwnd, "ENTER", 1, false);
						break;
					}

					case '(':
					case ')': {
						// FIXME - implement group parser
						break;
					}

					case '{':
					case '}': {
						// FIXME - implement symbol parser
						break;
					}

					default: {
						SendKey(hwnd, key_string[i], 1);
						break;
					}
				}

				

				if (shift_reset > 0) {
					shift_reset--;
					if (shift_reset == 0) {
						SendSymbol(hwnd, "SHIFT", 1, false);
					}
				}

				if (control_reset > 0) {
					control_reset--;
					if (control_reset == 0) {
						SendSymbol(hwnd, "CONTROL", 1, false);
					}
				}

				if (alt_reset > 0) {
					alt_reset--;
					if (alt_reset == 0) {
						SendSymbol(hwnd, "ALT", 1, false);
					}
				}
			}
		}

		public static void SendWait(string keys) {
			Send(keys);
			Flush();
		}
		#endregion	// Public Instance Properties
	}
}