/// <summary> /// Sends a key to a process without it being active /// </summary> public static void SendKey(this Process p, KeyCode kc, SendKeyType kt) { if (p == null) { throw new ArgumentNullException("p"); } IntPtr editHwnd = FindWindowEx(p.MainWindowHandle, (IntPtr)0, "Edit", null); switch (kt) { case SendKeyType.KeyUp: PostMessage(editHwnd, new IntPtr(WM_KEYUP), (int)kc, 0); break; case SendKeyType.KeyDown: PostMessage(editHwnd, new IntPtr(WM_KEYDOWN), (int)kc, 0); break; case SendKeyType.KeyPress: PostMessage(editHwnd, new IntPtr(WM_KEYDOWN), (int)kc, 0); Thread.Sleep(50); PostMessage(editHwnd, new IntPtr(WM_KEYUP), (int)kc, 0); break; default: throw new ArgumentOutOfRangeException("kt"); } }
/// <summary> /// Sends a key to a process without it being active /// </summary> public static void SendKey(this ProcessInfo p, KeyCode kc, SendKeyType kt) { if (p == null) { throw new ArgumentNullException("p"); } p.ToProcess().SendKey(kc, kt); }
public globalmouse_hook(SendKeyType xbutton1, SendKeyType xbutton2) { m_handle = kernel32.LoadLibrary("mousehook.dll"); if (m_handle == IntPtr.Zero) { MessageBox.Show("mousehook.dll 의 읽기에 실패"); return; } IntPtr func = kernel32.GetProcAddress(m_handle, "SetDolMouseHookEx"); if (func == IntPtr.Zero) { MessageBox.Show("SetDolMouseHookEx() 의 주소 획득 실패"); return; } SetDolMouseHookEx setDolMouseHook = (SetDolMouseHookEx)Marshal.GetDelegateForFunctionPointer(func, typeof(SetDolMouseHookEx)); setDolMouseHook((int)xbutton1, (int)xbutton2); }
/// <summary> /// Sends a key to a process without it being active /// </summary> public static void SendKey(this Process p, KeyCode kc,SendKeyType kt) { if (p==null) throw new ArgumentNullException("p"); IntPtr editHwnd = FindWindowEx(p.MainWindowHandle, (IntPtr)0, "Edit", null); switch (kt) { case SendKeyType.KeyUp: PostMessage(editHwnd, new IntPtr(WM_KEYUP), (int)kc, 0); break; case SendKeyType.KeyDown: PostMessage(editHwnd, new IntPtr(WM_KEYDOWN), (int)kc, 0); break; case SendKeyType.KeyPress: PostMessage(editHwnd, new IntPtr(WM_KEYDOWN), (int)kc, 0); Thread.Sleep(50); PostMessage(editHwnd, new IntPtr(WM_KEYUP), (int)kc, 0); break; default: throw new ArgumentOutOfRangeException("kt"); } }
/// <summary> /// Sends a key to a process without it being active /// </summary> public static void SendKey(this ProcessInfo p, KeyCode kc ,SendKeyType kt) { if (p == null) throw new ArgumentNullException("p"); p.ToProcess().SendKey(kc, kt); }