WinAPI

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace MineMan
{
    public class WinAPI
    {
        //
        //  內存讀取部分
        //
        [DllImport("kernel32.dll")] // 打開內存讀取
        public static extern IntPtr OpenProcess(int dwDesiredAccess, int bInheritHandle, int dwProcessId);

        [DllImport("kernel32.dll")] // 關閉內存讀取
        public static extern Int32 CloseHandle(IntPtr hObject);

        [DllImport("kernel32.dll")] // 讀取內存
        public static extern int ReadProcessMemory(IntPtr hProcess, int lpBaseAddress, ref int lpBuffer, int nSize, int lpNumberOfBytesWritten);


        //
        //  鼠標控制部分
        //
        [DllImport("User32")]   // 設置鼠標位置
        public extern static int SetCursorPos(int x, int y);

        [DllImport("User32")]   // 隱藏或顯示鼠標
        public extern static int ShowCursor(bool bShow);

        [DllImport("user32")]   // 模擬鼠標事件
        public extern static void mouse_event(int dwFlags, int dx, int dy, int dwData, IntPtr dwExtraInfo);


        //
        //  窗體相關部分
        //
        [DllImport("USER32.DLL")]   // 查找窗體句柄
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("USER32.DLL")]   // 設置窗體置頂
        public static extern bool SetForegroundWindow(IntPtr hWnd);

        [DllImport("user32")]       // 獲得窗體位置
        public static extern bool GetWindowRect(IntPtr hwnd, ref RECT lpRect);

        public struct RECT          // 用於接受窗體位置的RECT結構,順序不可更改
        {
            public int left;    // 窗體最左邊,距離屏幕左邊的值
            public int top;     // 窗體最上邊,距離屏幕上邊的值
            public int right;   // 窗體最右邊,距離屏幕左邊的值
            public int bottom;  // 窗體最右邊,距離屏幕上邊的值
        }


        //
        //  系統熱鍵部分
        //
        [DllImport("USER32.DLL")]   // 註冊熱鍵
        public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint control, System.Windows.Forms.Keys vk);

        [DllImport("USER32.DLL")]   // 卸載熱鍵
        public static extern bool UnregisterHotKey(IntPtr hWnd, int id);
    }
}

原文地址:https://www.cnblogs.com/yellowapplemylove/p/2021590.html