public void ConvertToRaw() { recorder.Entries.Clear(); MacroRecordEntry newEntry; Win32Input input; foreach (MacroRecordingsDataSet.MacroEntriesRow row in dataTable) { input = new Win32Input(); if (row.IsActionNull()) // kb input { input.type = 1; input.ki = new KBInput(); input.ki.wVk = (ushort)System.Windows.Input.KeyInterop.VirtualKeyFromKey( (System.Windows.Input.Key)Enum.Parse(typeof(System.Windows.Input.Key), row.Key)); input.ki.dwFlags |= (row.Pressed ? (uint)KBEvents.KEYUP : 0); } else // mouse input { input.type = 0; input.mi = new MouseInput(); input.mi.dx = (int)(row.X * (65535f / (Screen.PrimaryScreen.Bounds.Width))); input.mi.dy = (int)(row.Y * (65535f / Screen.PrimaryScreen.Bounds.Height)); int evt = (int)Enum.Parse(typeof(MouseEvents), row.Action); evt |= (int)MouseEvents.ABSOLUTE; input.mi.dwFlags = (uint)evt; } newEntry = new MacroRecordEntry(input, row.Time); recorder.Entries.Add(newEntry); } }
private void kbHook_KeyIntercepted(int msg, int vkCode, int scanCode, int flags, int time, IntPtr dwExtraInfo, ref bool handled) { Win32Input input = new Win32Input(); input.type = 1; input.ki = new KBInput(); KBMessages kbMessage = (KBMessages)msg; KBEvents evt = 0; switch (kbMessage) { case KBMessages.WM_KEYUP: evt = KBEvents.KEYUP; break; default: break; } input.ki.dwFlags = (uint)evt; input.ki.time = 0; input.ki.wVk = (ushort)vkCode; input.ki.wScan = (ushort)scanCode; input.mi.dwExtraInfo = IntPtr.Zero; macroEntries.Add(new MacroRecordEntry(input, watch.ElapsedMilliseconds)); }
public void Play() { long lastTime = 0; for (int i = 0; i < macroEntries.Count; i++) { Win32Input input = macroEntries[i].Input; long currentTime = macroEntries[i].Time; System.Threading.Thread.Sleep((int)(currentTime - lastTime)); lastTime = currentTime; LowLevelInput.SendInput(1, ref input, Marshal.SizeOf(typeof(Win32Input))); } }
public MacroRecordEntry(Win32Input input, long time) { Input = input; Time = time; }
private void msHook_MouseIntercepted(int msg, ManagedWinapi.Windows.POINT pt, int mouseData, int flags, int time, IntPtr dwExtraInfo, ref bool handled) { MouseEvents evt = 0; Win32Input input = new Win32Input(); MouseMessages mouseMessage = (MouseMessages)msg; input.type = 0; input.mi = new MouseInput(); input.mi.dx = (int)(pt.X * (65535f / (Screen.PrimaryScreen.Bounds.Width))); input.mi.dy = (int)(pt.Y * (65535f / Screen.PrimaryScreen.Bounds.Height)); input.mi.mouseData = 0; switch (mouseMessage) { case MouseMessages.WM_MOUSEMOVE: evt = MouseEvents.MOVE; break; case MouseMessages.WM_LBUTTONDOWN: evt = MouseEvents.LEFTDOWN; break; case MouseMessages.WM_LBUTTONUP: evt = MouseEvents.LEFTUP; break; case MouseMessages.WM_MBUTTONDOWN: evt = MouseEvents.MIDDLEDOWN; break; case MouseMessages.WM_MBUTTONUP: evt = MouseEvents.MIDDLEUP; break; case MouseMessages.WM_RBUTTONDOWN: evt = MouseEvents.RIGHTDOWN; break; case MouseMessages.WM_RBUTTONUP: evt = MouseEvents.RIGHTUP; break; case MouseMessages.WM_MOUSEWHEEL: case MouseMessages.WM_MOUSEHWHEEL: evt = MouseEvents.WHEEL; input.mi.mouseData = (uint)(mouseData >> 16); break; case MouseMessages.WM_XBUTTONDOWN: evt = MouseEvents.XDOWN; input.mi.mouseData = (uint)(mouseData >> 16); break; case MouseMessages.WM_XBUTTONUP: evt = MouseEvents.XUP; input.mi.mouseData = (uint)(mouseData >> 16); break; default: break; } evt |= MouseEvents.ABSOLUTE; input.mi.dwFlags = (uint)evt; input.mi.time = 0; input.mi.dwExtraInfo = IntPtr.Zero; macroEntries.Add(new MacroRecordEntry(input, watch.ElapsedMilliseconds)); }