/// <summary> /// Gets the recorded action datas. /// </summary> /// <returns></returns> public object[] GetDatas() { List<object> datas = new List<object>(); XmlReader reader = XmlReader.Create(this.actionsListFileName); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "Action") { //效率,会初始化两次 if (reader.HasAttributes) { string type = reader.GetAttribute("Type"); int delayTime = Convert.ToInt32(reader.GetAttribute("DelayTime")); if (type == "KeyboardAct") { Win32API.KeyEvent keyEvent = new Win32API.KeyEvent(); keyEvent.delayTime = delayTime; while (reader.Read()) { //throgh if statement never be true if (reader.NodeType == XmlNodeType.Element && reader.Name == "KeyData") { keyEvent.bVk = Convert.ToInt32(reader.ReadInnerXml()); if (reader.NodeType == XmlNodeType.Element && reader.Name == "KeyEvent") { string eventName = reader.ReadInnerXml(); if (eventName == KeyboardEvents.WM_KeyUp.ToString()) { keyEvent.dwFlags = Win32API.KBEventFlag.KeyUp; } else if (eventName == KeyboardEvents.WM_KeyDown.ToString()) { keyEvent.dwFlags = Win32API.KBEventFlag.KeyDown; } break; } else { keyEvent = JudgeKeyevent(reader, keyEvent); break; } } } datas.Add(keyEvent); } else if (type == "MouseAct") { Win32API.MouseEvent MouseEvent = new Win32API.MouseEvent(); MouseEvent.delayTime = delayTime; while (reader.Read()) { //throgh if statement never be true if (reader.NodeType == XmlNodeType.Element && reader.Name == "Position") { string pointInfo = reader.ReadInnerXml(); pointInfo = pointInfo.Substring(1, pointInfo.Length - 2); string[] xy = (pointInfo.Split(',')); MouseEvent.pt.x = Convert.ToInt32(xy[0]); MouseEvent.pt.y = Convert.ToInt32(xy[1]); if (reader.NodeType == XmlNodeType.Element && reader.Name == "MouseEvent") { string eventName = reader.ReadInnerXml(); MouseEvent = JudgeMouseEvent(MouseEvent, eventName); break; } else { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "MouseEvent") { string eventName = reader.ReadInnerXml(); MouseEvent = JudgeMouseEvent(MouseEvent, eventName); break; } } break; } } } datas.Add(MouseEvent); } } } } reader.Close(); return datas.ToArray(); }
/// <summary> /// Gets the recorded action datas. /// </summary> /// <returns></returns> public Win32API.MouseEvent[] GetDatas() { List<Win32API.MouseEvent> datas = new List<Win32API.MouseEvent>(); XmlReader reader = XmlReader.Create(this.actionsListFileName); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "Action") { //效率,会初始化两次 if (reader.HasAttributes) { Win32API.MouseEvent mouseEvent = new Win32API.MouseEvent(); mouseEvent.delayTime = Convert.ToInt32(reader.GetAttribute("DelayTime")); while (reader.Read()) { //throgh if statement never be true if (reader.NodeType == XmlNodeType.Element && reader.Name == "Position") { string pointInfo = reader.ReadInnerXml(); pointInfo = pointInfo.Substring(1, pointInfo.Length - 2); string[] xy = (pointInfo.Split(',')); mouseEvent.pt.x = Convert.ToInt32(xy[0]); mouseEvent.pt.y = Convert.ToInt32(xy[1]); if (reader.NodeType == XmlNodeType.Element && reader.Name == "MouseEvent") { string eventName = reader.ReadInnerXml(); switch (eventName) { case "WM_MOUSEMOVE": mouseEvent.dwFlags = Win32API.MouseEventFlag.Move; break; case "WM_LBUTTONDOWN": mouseEvent.dwFlags = Win32API.MouseEventFlag.LeftDown; break; case "WM_LBUTTONUP": mouseEvent.dwFlags = Win32API.MouseEventFlag.LeftUp; break; case "WM_LBUTTONDBLCLK": //MouseEvent.dwFlags = Win32API.MouseEventFlag break; case "WM_RBUTTONDOWN": mouseEvent.dwFlags = Win32API.MouseEventFlag.RightDown; break; case "WM_RBUTTONUP": mouseEvent.dwFlags = Win32API.MouseEventFlag.RightUp; break; case "WM_RBUTTONDBLCLK": break; case "WM_MBUTTONDOWN": mouseEvent.dwFlags = Win32API.MouseEventFlag.MiddleDown; break; case "WM_MBUTTONUP": mouseEvent.dwFlags = Win32API.MouseEventFlag.MiddleUp; break; case "WM_MBUTTONDBLCLK": break; case "WM_MOUSEWHEEL": mouseEvent.dwFlags = Win32API.MouseEventFlag.Wheel; break; default: break; } break; } else { while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element && reader.Name == "MouseEvent") { string eventName = reader.ReadInnerXml(); switch (eventName) { case "WM_MOUSEMOVE": mouseEvent.dwFlags = Win32API.MouseEventFlag.Move; break; case "WM_LBUTTONDOWN": mouseEvent.dwFlags = Win32API.MouseEventFlag.LeftDown; break; case "WM_LBUTTONUP": mouseEvent.dwFlags = Win32API.MouseEventFlag.LeftUp; break; case "WM_LBUTTONDBLCLK": //MouseEvent.dwFlags = Win32API.MouseEventFlag break; case "WM_RBUTTONDOWN": mouseEvent.dwFlags = Win32API.MouseEventFlag.RightDown; break; case "WM_RBUTTONUP": mouseEvent.dwFlags = Win32API.MouseEventFlag.RightUp; break; case "WM_RBUTTONDBLCLK": break; case "WM_MBUTTONDOWN": mouseEvent.dwFlags = Win32API.MouseEventFlag.MiddleDown; break; case "WM_MBUTTONUP": mouseEvent.dwFlags = Win32API.MouseEventFlag.MiddleUp; break; case "WM_MBUTTONDBLCLK": break; case "WM_MOUSEWHEEL": mouseEvent.dwFlags = Win32API.MouseEventFlag.Wheel; break; default: break; } break; } } break; } } } datas.Add(mouseEvent); } } } reader.Close(); return datas.ToArray(); }