1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
23 // Peter Bartok (pbartok@novell.com)
29 using System.Collections;
31 namespace System.Windows.Forms {
32 public class SendKeys {
33 #region Local variables
34 private static Queue keys = new Queue();
37 #region Private methods
41 private static IntPtr CharToVKey(char key) {
42 // FIXME - build a table to translate between vkeys and chars
43 throw new NotImplementedException();
46 private static IntPtr SymbolToVKey(string symbol) {
47 // FIXME - build a table to translate between vkeys and symbols
48 throw new NotImplementedException();
51 private static void SendSymbol(IntPtr hwnd, string symbol, int repeat_count, bool down) {
55 for (int i = 0; i < repeat_count; i++ ) {
58 msg.message = Msg.WM_KEYDOWN;
59 msg.wParam = SymbolToVKey(symbol);
60 msg.lParam = IntPtr.Zero;
67 msg.message = Msg.WM_KEYUP;
68 msg.wParam = SymbolToVKey(symbol);
69 msg.lParam = IntPtr.Zero;
75 private static void SendKey(IntPtr hwnd, char key, int repeat_count) {
78 for (int i = 0; i < repeat_count; i++ ) {
81 msg.message = Msg.WM_KEYDOWN;
82 msg.wParam = CharToVKey(key);
83 msg.lParam = IntPtr.Zero;
90 msg.message = Msg.WM_KEYUP;
91 msg.wParam = CharToVKey(key);
92 msg.lParam = IntPtr.Zero;
97 #endregion // Private Methods
99 #region Public Static Methods
100 public static void Flush() {
103 // FIXME - we only send to our own app, instead of the active app
104 while (keys.Count > 0) {
105 msg = (MSG)keys.Dequeue();
106 XplatUI.TranslateMessage (ref msg);
107 XplatUI.DispatchMessage (ref msg);
112 public static void Send(string key_string) {
118 hwnd = XplatUI.GetActive();
124 for (int i = 0; i < key_string.Length; i++) {
125 switch(key_string[i]) {
127 SendSymbol(hwnd, "SHIFT", 1, true);
133 SendSymbol(hwnd, "CONTROL", 1, true);
139 SendSymbol(hwnd, "ALT", 1, true);
145 SendSymbol(hwnd, "ENTER", 1, true);
146 SendSymbol(hwnd, "ENTER", 1, false);
152 // FIXME - implement group parser
158 // FIXME - implement symbol parser
163 SendKey(hwnd, key_string[i], 1);
170 if (shift_reset > 0) {
172 if (shift_reset == 0) {
173 SendSymbol(hwnd, "SHIFT", 1, false);
177 if (control_reset > 0) {
179 if (control_reset == 0) {
180 SendSymbol(hwnd, "CONTROL", 1, false);
186 if (alt_reset == 0) {
187 SendSymbol(hwnd, "ALT", 1, false);
193 public static void SendWait(string keys) {
197 #endregion // Public Instance Properties