public void Send() { NativeMethods.SendInput((uint)m_input.Count, m_input.ToArray(), Marshal.SizeOf(typeof(INPUT))); }
private static void SendString(string str) { List <VK> modifiers = new List <VK>(); bool use_gtk_hack = false, use_office_hack = false; const int len = 256; StringBuilder buf = new StringBuilder(len); var hwnd = NativeMethods.GetForegroundWindow(); if (NativeMethods.GetClassName(hwnd, buf, len) > 0) { string wclass = buf.ToString(); /* HACK: GTK+ applications behave differently with Unicode, and some * applications such as XChat for Windows rename their own top-level * window, so we parse through the names we know in order to detect * a GTK+ application. */ if (wclass == "gdkWindowToplevel" || wclass == "xchatWindowToplevel") { use_gtk_hack = true; } /* HACK: in MS Office, some symbol insertions change the text font * without returning to the original font. To avoid this, we output * a space character, then go left, insert our actual symbol, then * go right and backspace. */ /* These are the actual window class names for Outlook and Word… * TODO: PowerPoint ("PP(7|97|9|10)FrameClass") */ if (wclass == "rctrl_renwnd32" || wclass == "OpusApp") { use_office_hack = true && Settings.InsertZwsp.Value; } } /* Clear keyboard modifiers if we need one of our custom hacks */ if (use_gtk_hack || use_office_hack) { VK[] all_modifiers = new VK[] { VK.LSHIFT, VK.RSHIFT, VK.LCONTROL, VK.RCONTROL, VK.LMENU, VK.RMENU, }; foreach (VK vk in all_modifiers) { if ((NativeMethods.GetKeyState(vk) & 0x80) == 0x80) { modifiers.Add(vk); } } foreach (VK vk in modifiers) { SendKeyUp(vk); } } if (use_gtk_hack) { /* Wikipedia says Ctrl+Shift+u, release, then type the four hex * digits, and press Enter. * (http://en.wikipedia.org/wiki/Unicode_input). */ SendKeyDown(VK.LCONTROL); SendKeyDown(VK.LSHIFT); SendKeyPress((VK)'U'); SendKeyUp(VK.LSHIFT); SendKeyUp(VK.LCONTROL); foreach (var ch in str) { foreach (var key in String.Format("{0:X04} ", (short)ch)) { SendKeyPress((VK)key); } } } else { List <INPUT> input = new List <INPUT>(); if (use_office_hack) { input.Add(NewInputKey((ScanCodeShort)'\u200b')); input.Add(NewInputKey((VirtualKeyShort)VK.LEFT)); } for (int i = 0; i < str.Length; i++) { input.Add(NewInputKey((ScanCodeShort)str[i])); } if (use_office_hack) { input.Add(NewInputKey((VirtualKeyShort)VK.RIGHT)); } NativeMethods.SendInput((uint)input.Count, input.ToArray(), Marshal.SizeOf(typeof(INPUT))); } /* Restore keyboard modifiers if we needed one of our custom hacks */ if (use_gtk_hack || use_office_hack) { foreach (VK vk in modifiers) { SendKeyDown(vk); } } }