-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
571 additions
and
162 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,250 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace GameZBDAlchemyStoneTapper | ||
{ | ||
public class InputSender | ||
{ | ||
#region Imports/Structs/Enums | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
public struct KeyboardInput | ||
{ | ||
public ushort wVk; | ||
public ushort wScan; | ||
public uint dwFlags; | ||
public uint time; | ||
public IntPtr dwExtraInfo; | ||
} | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
public struct MouseInput | ||
{ | ||
public int dx; | ||
public int dy; | ||
public uint mouseData; | ||
public uint dwFlags; | ||
public uint time; | ||
public IntPtr dwExtraInfo; | ||
} | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
public struct HardwareInput | ||
{ | ||
public uint uMsg; | ||
public ushort wParamL; | ||
public ushort wParamH; | ||
} | ||
|
||
[StructLayout(LayoutKind.Explicit)] | ||
public struct InputUnion | ||
{ | ||
[FieldOffset(0)] public MouseInput mi; | ||
[FieldOffset(0)] public KeyboardInput ki; | ||
[FieldOffset(0)] public HardwareInput hi; | ||
} | ||
|
||
public struct Input | ||
{ | ||
public int type; | ||
public InputUnion u; | ||
} | ||
|
||
[Flags] | ||
public enum InputType | ||
{ | ||
Mouse = 0, | ||
Keyboard = 1, | ||
Hardware = 2 | ||
} | ||
|
||
[Flags] | ||
public enum KeyEventF | ||
{ | ||
KeyDown = 0x0000, | ||
ExtendedKey = 0x0001, | ||
KeyUp = 0x0002, | ||
Unicode = 0x0004, | ||
Scancode = 0x0008 | ||
} | ||
|
||
[Flags] | ||
public enum MouseEventF | ||
{ | ||
Absolute = 0x8000, | ||
HWheel = 0x01000, | ||
Move = 0x0001, | ||
MoveNoCoalesce = 0x2000, | ||
LeftDown = 0x0002, | ||
LeftUp = 0x0004, | ||
RightDown = 0x0008, | ||
RightUp = 0x0010, | ||
MiddleDown = 0x0020, | ||
MiddleUp = 0x0040, | ||
VirtualDesk = 0x4000, | ||
Wheel = 0x0800, | ||
XDown = 0x0080, | ||
XUp = 0x0100 | ||
} | ||
|
||
[DllImport("user32.dll", SetLastError = true)] | ||
private static extern uint SendInput(uint nInputs, Input[] pInputs, int cbSize); | ||
|
||
[DllImport("user32.dll")] | ||
private static extern IntPtr GetMessageExtraInfo(); | ||
|
||
[DllImport("user32.dll")] | ||
private static extern bool GetCursorPos(out POINT lpPoint); | ||
|
||
[StructLayout(LayoutKind.Sequential)] | ||
public struct POINT | ||
{ | ||
public int X; | ||
public int Y; | ||
} | ||
|
||
[DllImport("User32.dll")] | ||
private static extern bool SetCursorPos(int x, int y); | ||
|
||
#endregion Imports/Structs/Enums | ||
|
||
#region Wrapper Methods | ||
|
||
public static POINT GetCursorPosition() | ||
{ | ||
GetCursorPos(out POINT point); | ||
return point; | ||
} | ||
|
||
public static void SetCursorPosition(int x, int y) | ||
{ | ||
SetCursorPos(x, y); | ||
} | ||
|
||
public static void SendKeyboardInput(KeyboardInput[] kbInputs) | ||
{ | ||
Input[] inputs = new Input[kbInputs.Length]; | ||
|
||
for (int i = 0; i < kbInputs.Length; i++) | ||
{ | ||
inputs[i] = new Input | ||
{ | ||
type = (int)InputType.Keyboard, | ||
u = new InputUnion | ||
{ | ||
ki = kbInputs[i] | ||
} | ||
}; | ||
} | ||
|
||
SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(Input))); | ||
} | ||
|
||
public static void ClickKey(ushort scanCode) | ||
{ | ||
var inputs = new KeyboardInput[] | ||
{ | ||
new KeyboardInput | ||
{ | ||
wScan = scanCode, | ||
dwFlags = (uint)(KeyEventF.KeyDown | KeyEventF.Scancode), | ||
dwExtraInfo = GetMessageExtraInfo() | ||
}, | ||
new KeyboardInput | ||
{ | ||
wScan = scanCode, | ||
dwFlags = (uint)(KeyEventF.KeyUp | KeyEventF.Scancode), | ||
dwExtraInfo = GetMessageExtraInfo() | ||
} | ||
}; | ||
SendKeyboardInput(inputs); | ||
} | ||
|
||
public static void SendMouseInput(MouseInput[] mInputs) | ||
{ | ||
Input[] inputs = new Input[mInputs.Length]; | ||
|
||
for (int i = 0; i < mInputs.Length; i++) | ||
{ | ||
inputs[i] = new Input | ||
{ | ||
type = (int)InputType.Mouse, | ||
u = new InputUnion | ||
{ | ||
mi = mInputs[i] | ||
} | ||
}; | ||
} | ||
|
||
SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(Input))); | ||
} | ||
|
||
#endregion Wrapper Methods | ||
|
||
public static void LeftClick() | ||
{ | ||
Input[] inputs = new Input[] | ||
{ | ||
new Input | ||
{ | ||
type = (int) InputType.Mouse, | ||
u = new InputUnion | ||
{ | ||
mi = new MouseInput | ||
{ | ||
dwFlags = (uint)( MouseEventF.LeftDown), | ||
dwExtraInfo = GetMessageExtraInfo() | ||
} | ||
} | ||
}, | ||
new Input | ||
{ | ||
type = (int) InputType.Mouse, | ||
u = new InputUnion | ||
{ | ||
mi = new MouseInput | ||
{ | ||
dwFlags = (uint)MouseEventF.LeftUp, | ||
dwExtraInfo = GetMessageExtraInfo() | ||
} | ||
} | ||
} | ||
}; | ||
|
||
SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(Input))); | ||
} | ||
|
||
public static void RightClick() | ||
{ | ||
Input[] inputs = new Input[] | ||
{ | ||
new Input | ||
{ | ||
type = (int) InputType.Mouse, | ||
u = new InputUnion | ||
{ | ||
mi = new MouseInput | ||
{ | ||
dwFlags = (uint)( MouseEventF.RightDown), | ||
dwExtraInfo = GetMessageExtraInfo() | ||
} | ||
} | ||
}, | ||
new Input | ||
{ | ||
type = (int) InputType.Mouse, | ||
u = new InputUnion | ||
{ | ||
mi = new MouseInput | ||
{ | ||
dwFlags = (uint)MouseEventF.RightUp, | ||
dwExtraInfo = GetMessageExtraInfo() | ||
} | ||
} | ||
} | ||
}; | ||
|
||
SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(Input))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using GregsStack.InputSimulatorStandard; | ||
using NumSharp.Utilities; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
using static GameZBDAlchemyStoneTapper.InputSender; | ||
|
||
namespace GameZBDAlchemyStoneTapper | ||
{ | ||
internal class MouseClickHelper | ||
{ | ||
private static InputSimulator Ins = new InputSimulator(); | ||
|
||
[DllImport("user32.dll")] | ||
private static extern void mouse_event(int dwFlags, int dx, int dy, | ||
int dwData, int dwExtraInfo); | ||
|
||
[DllImport("user32.dll", EntryPoint = "SetCursorPos")] | ||
private static extern void SetCursorPos(int X, int Y); | ||
|
||
[Flags] | ||
public enum MouseEventFlags | ||
{ | ||
LEFTDOWN = 0x00000002, | ||
LEFTUP = 0x00000004, | ||
MIDDLEDOWN = 0x00000020, | ||
MIDDLEUP = 0x00000040, | ||
MOVE = 0x00000001, | ||
ABSOLUTE = 0x00008000, | ||
RIGHTDOWN = 0x00000008, | ||
RIGHTUP = 0x00000010 | ||
} | ||
|
||
public static void LeftClick(int x, int y) | ||
{ | ||
SetCursorPos(x, y); | ||
Thread.Sleep(50); | ||
Ins.Mouse.LeftButtonDown(); | ||
Thread.Sleep(50); | ||
Ins.Mouse.LeftButtonUp(); | ||
} | ||
|
||
public static void LeftClick(Point pt) | ||
{ | ||
SetCursorPos(pt.X, pt.Y); | ||
Thread.Sleep(50); | ||
Ins.Mouse.LeftButtonDown(); | ||
Thread.Sleep(50); | ||
Ins.Mouse.LeftButtonUp(); | ||
} | ||
|
||
public static void RightClick(int x, int y) | ||
{ | ||
SetCursorPos(x, y); | ||
Thread.Sleep(50); | ||
Ins.Mouse.RightButtonDown(); | ||
Thread.Sleep(50); | ||
Ins.Mouse.RightButtonUp(); | ||
} | ||
|
||
public static void RightClick(Point pt) | ||
{ | ||
SetCursorPos(pt.X, pt.Y); | ||
Thread.Sleep(50); | ||
Ins.Mouse.RightButtonDown(); | ||
Thread.Sleep(50); | ||
Ins.Mouse.RightButtonUp(); | ||
} | ||
|
||
public static void PressSpace() | ||
{ | ||
Ins.Keyboard.KeyPress(GregsStack.InputSimulatorStandard.Native.VirtualKeyCode.SPACE); | ||
} | ||
|
||
public static void PressEnter() | ||
{ | ||
Ins.Keyboard.KeyPress(GregsStack.InputSimulatorStandard.Native.VirtualKeyCode.EXECUTE); | ||
} | ||
} | ||
} |
Oops, something went wrong.