//输出的时候
MouseEventArgs mouseArgs为{X=189 Y=168}
//我定义了一个
string str="X=189 Y=168"
用什么办法把str转换成MouseEventArgs或者EventArgs类型?本人菜鸟,求高手解决。
MouseEventArgs mouseArgs为{X=189 Y=168}
//我定义了一个
string str="X=189 Y=168"
用什么办法把str转换成MouseEventArgs或者EventArgs类型?本人菜鸟,求高手解决。
public enum MacroEventType
{
MouseMove,
MouseDown,
MouseUp,
MouseWheel,
KeyDown,
KeyUp,
KeyPress
} /// <summary>
/// Series of events that can be recorded any played back
/// </summary>
[Serializable]
public class MacroEvent
{ public MacroEventType MacroEventType;
public EventArgs EventArgs;
public int TimeSinceLastEvent; public MacroEvent(MacroEventType macroEventType, EventArgs eventArgs, int timeSinceLastEvent)
{ MacroEventType = macroEventType;
EventArgs = eventArgs;
TimeSinceLastEvent = timeSinceLastEvent; }
}
void mouseHook_MouseMove(object sender, MouseEventArgs e)
{ events.Add(
new MacroEvent(
MacroEventType.MouseMove,
e,
Environment.TickCount - lastTimeRecorded
)); lastTimeRecorded = Environment.TickCount; } case MacroEventType.MouseMove:
{ MouseEventArgs mouseArgs = (MouseEventArgs)macroEvent.EventArgs; MouseSimulator.X = mouseArgs.X;
MouseSimulator.Y = mouseArgs.Y; }
break;
{
var xy = str.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
var ret = new YourClass();
foreach (var x in xy)
{
var ex = x.Split(new char[] { '=' }, 2);
if (ex[0].Trim().ToUpper() == "X")
ret.x = int.Parse(ex[1]);
else if (ex[0].Trim().ToUpper() == "Y")
ret.y = int.Parse(ex[1]);
}
return ret;
}
ret.y 改为 ret.Y
说高级一点就是给你一个鼠标x,y位置如何转换成MouseEventArgs e
MouseMove,X=631 Y=326
像这样我把鼠标的动作输出到了文本文件,现在我想还原成鼠标事件,不知道这样说明白了没有?
string str = "X=189 Y=168";
Match match = System.Text.RegularExpressions.Regex.Match(str, "X=([0-9]+) Y=([0-9]+)");
int x = int.Parse(match.Groups[1].Value);
int y = int.Parse(match.Groups[2].Value);
MouseEventArgs e = new MouseEventArgs(MouseButtons.Left, 1, x, y, 0);
说高级一点就是给你一个鼠标x,y位置如何转换成MouseEventArgs e又变成“给你一个鼠标x,y位置”了?不是string了?代码都有了,就看你能不能自己读懂了。