Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

Send Input Simulate Mouse Click to Focus Window

Hi All Insomniac ! 😴
Send Input Simulate Mouse Click to Focus !.
Pinvoke structs:

Code
public const int INPUT_MOUSE = 0;
public const int INPUT_KEYBOARD = 1;
public const int INPUT_HARDWARE = 2;

[Flags]
public enum MOUSEEVENTF : uint
{
MOUSEEVENTF_ABSOLUTE = 0x8000,
MOUSEEVENTF_LEFTDOWN = 0x0002,
MOUSEEVENTF_LEFTUP = 0x0004,
MOUSEEVENTF_MIDDLEDOWN = 0x0020,
MOUSEEVENTF_MIDDLEUP = 0x0040,
MOUSEEVENTF_MOVE = 0x0001,
MOUSEEVENTF_RIGHTDOWN = 0x0008,
MOUSEEVENTF_RIGHTUP = 0x0010,
MOUSEEVENTF_XDOWN = 0x0080,
MOUSEEVENTF_XUP = 0x0100,
MOUSEEVENTF_WHEEL = 0x0800,
MOUSEEVENTF_HWHEEL = 0x01000,
}

[StructLayout(LayoutKind.Sequential)]
internal struct MOUSEINPUT
{
    internal int dx;
    internal int dy;
    internal int mouseData;
    internal MOUSEEVENTF dwFlags;
    internal uint time;
    internal UIntPtr dwExtraInfo;
}

[StructLayout(LayoutKind.Sequential)]
public struct KEYBDINPUT
{
    public ushort wVk;
    public ushort wScan;
    public uint dwFlags;
    public uint time;
    public IntPtr dwExtraInfo;
}

[StructLayout(LayoutKind.Sequential)]
public struct HARDWAREINPUT
{
    uint uMsg;
    ushort wParamL;
    ushort wParamH;
}

[StructLayout(LayoutKind.Explicit)]
public struct INPUT
{
    [FieldOffset(0)]
    public int type;
    [FieldOffset(4)] //*
    public MOUSEINPUT mi;
    [FieldOffset(4)] //*
    public KEYBDINPUT ki;
    [FieldOffset(4)] //*
    public HARDWAREINPUT hi;
}
Code

Code
[DllImport("user32.dll")]
internal static extern uint SendInput(uint nInputs, [MarshalAs(UnmanagedType.LPArray), In] INPUT[] pInputs, int cbSize);

[DllImport("user32.dll")]
public static extern IntPtr SetFocus(IntPtr hWnd);

Process proc = Process.GetProcessesByName("ac_client")[0];

uint hwnd = (uint)proc.MainWindowHandle.ToInt32();

INPUT[] mInput = new INPUT[1];
mInput[0].type = INPUT_MOUSE;
mInput[0].mi.dwFlags = MOUSEEVENTF.MOUSEEVENTF_LEFTDOWN;

SetFocus(proc.MainWindowHandle);

SendInput(hwnd, mInput, System.Runtime.InteropServices.Marshal.SizeOf(mInput[0]));
I wonder if you could send a mouse click to a certain position on the GUI screen.
May you be given directions by software engineer document writers.
(Oct 21, 2020 04:43 AM)saltycracker Wrote:  I wonder if you could send a mouse click to a certain position on the GUI screen.

Casualgamer has good videos on mouse click events.

https://www.youtube.com/watch?v=j4VFo4acorQ


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by SurHommeOct 1, 2022 03:25 PM 9 296 Oct 1, 2022 03:25 PM
Last Post: MeyerWolfsheim
[C#] by salemxx66Jan 4, 2022 07:43 PM 2 181 Jan 4, 2022 07:43 PM
Last Post: Tyzx159
[Python] by salemxx66Nov 1, 2021 10:17 AM 5 158 Nov 1, 2021 10:17 AM
Last Post: Maquina