I'm making a little bot in C#.
At the moment it works pretty well, it can load text from a file and type it for you.
I'd like to share the program with my friends. But I'm stumbling on a litlle problem.
As resolutions change, the buttons and textfields change position.
That's why I'd like to allow my friends to write the mouseposition is a XML-file, that I load in my program.
To load in the variables, I'm using this script:
private void Initialize() {
XmlTextReader reader = new XmlTextReader(Application.StartupPath + @"..\..\..\CursorPositions.xml");
while (reader.Read()) {
switch (reader.NodeType) {
case XmlNodeType.Element: // The node is an element.
element = reader.Value;
break;
case XmlNodeType.Text: //Display the text in each element.
switch (element) {
case "Textbox-X":
textX = int.Parse(reader.Value);
break;
case "Textbox-Y":
textY = int.Parse(reader.Value);
break;
case "SliderBegin-X":
sliderX = int.Parse(reader.Value);
break;
case "SliderBegin-Y":
sliderY = int.Parse(reader.Value);
break;
case "SubmitButton-X":
submitX = int.Parse(reader.Value);
break;
case "SubmitButton-Y":
submitY = int.Parse(reader.Value);
break;
}
break;
}
}
And this is my XML file:
<?xml version="1.0" encoding="utf-8" ?>
<CursorPositions>
<Textbox-X>430</Textbox-X>
<Textbox-Y>270</Textbox-Y>
<SliderBegin-X>430</SliderBegin-X>
<SliderBegin-Y>470</SliderBegin-Y>
<SubmitButton-X>860</SubmitButton-X>
<SubmitButton-Y>365</SubmitButton-Y>
</CursorPositions>
The Schema looks like this:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="CursorPositions">
<xs:complexType>
<xs:sequence>
<xs:element name="Textbox-X" type="xs:unsignedShort" />
<xs:element name="Textbox-Y" type="xs:unsignedShort" />
<xs:element name="SliderBegin-X" type="xs:unsignedShort" />
<xs:element name="SliderBegin-Y" type="xs:unsignedShort" />
<xs:element name="SubmitButton-X" type="xs:unsignedShort" />
<xs:element name="SubmitButton-Y" type="xs:unsignedShort" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Sadly enough, on testing, this always returns {0,0}.
Does anyone know what's wrong?
Or maybe you have a solution?
PS: for those who want to know, moving the mouse works like this:
private void MoveMouse(int X, int Y) {
Cursor.Position = new Point(X, Y);
mouse_event(MOUSEEVENTF_LEFTDOWN, X, Y, 0, 0); // press left mouse button
mouse_event(MOUSEEVENTF_LEFTUP, X, Y, 0, 0); // release left mouse button
}
You do need to include this part in the top of your code:
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
public const int MOUSEEVENTF_LEFTDOWN = 0x0002;
public const int MOUSEEVENTF_LEFTUP = 0x0004;
public const int MOUSEEVENTF_RIGHTDOWN = 0x0008;
public const int MOUSEEVENTF_RIGHTUP = 0x0010;