【发布时间】:2019-04-20 00:51:41
【问题描述】:
我正在尝试创建一个简单的自动访问程序。 使用该代码捕获只会保存灰色图片。 我该怎么办? 其他非游戏程序正常捕获。 是因为安全程序吗? 我尝试在该游戏中输入键盘,但它根本不起作用。
- SendKeys.SendWait("W")
- SendKeys.Send("W")
- 输入模拟器
- 发送输入
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Drawing.Imaging;
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
[System.Runtime.InteropServices.DllImport("User32", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
String AppPlayerName = "LOST ARK (64-bit) v.1.0.1.3";
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool PrintWindow(IntPtr hwnd, IntPtr hDC, uint nFlags);
[DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowRgn(IntPtr hWnd, IntPtr hRgn);
[DllImport("gdi32.dll")]
static extern IntPtr CreateRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
IntPtr findwindow = FindWindow(null, AppPlayerName);
if (findwindow != IntPtr.Zero)
{
Debug.WriteLine("Found.");
Debug.WriteLine(findwindow.ToString());
PrintWindow(findwindow);
}
else
{
Debug.WriteLine("Not Found");
}
}
public static void PrintWindow(IntPtr hwnd)
{
Rectangle rc = Rectangle.Empty;
Graphics gfxWin = Graphics.FromHwnd(hwnd);
rc = Rectangle.Round(gfxWin.VisibleClipBounds);
Bitmap bmp = new Bitmap(rc.Width, rc.Height, PixelFormat.Format32bppArgb);
Graphics gfxBmp = Graphics.FromImage(bmp);
IntPtr hdcBitmap = gfxBmp.GetHdc();
bool succeeded = PrintWindow(hwnd, hdcBitmap, 1);
gfxBmp.ReleaseHdc(hdcBitmap);
if (!succeeded)
{
gfxBmp.FillRectangle(
new SolidBrush(Color.Gray),
new Rectangle(Point.Empty, bmp.Size));
}
IntPtr hRgn = CreateRectRgn(0, 0, 0, 0);
GetWindowRgn(hwnd, hRgn);
Region region = Region.FromHrgn(hRgn);
if (!region.IsEmpty(gfxBmp))
{
gfxBmp.ExcludeClip(region);
gfxBmp.Clear(Color.Transparent);
}
gfxBmp.Dispose();
bmp.Save(Application.StartupPath + "1.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
【问题讨论】: