c# - 在线游戏中打印窗口不捕获
问题描述
我正在尝试创建一个简单的自动访问程序。使用该代码捕获只会保存灰色图片。我应该怎么办?其他非游戏程序正常捕获。是因为安全程序吗?我试图在那个游戏中输入一个键盘,但它根本不起作用。
- 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)
{
}
}
}
解决方案
游戏不使用 GDI 来显示内容。您的程序是创建一个 GDI 对象(图形)并从中复制内容。但游戏和 3d 编辑器都使用 DirectX、OpenGL 或任何其他直接访问视频的方式。它们绕过了 GDI 级别。
在过去,它被称为剧院模式。
请使用这篇文章,当游戏使用directx时:
推荐阅读
- php - 如何自定义laravel登录添加万能密钥?
- c# - 窗口打开时文本消失
- d3.js - 在 d3 条形图中的数据集之间切换
- css - Firefox 和边缘宽度的问题
- ios - UICollectionView。如何在没有动画的情况下使用不同的元素(不仅是第一个)呈现 viewController?
- casting - OpenGL ES 2.0 类型转换
- javascript - 使用 ajax 和 jquery 提交表单
- javascript - Angular 6:数据不显示在前端
- java - 获取 TimerTask 计划运行的下一次时间
- python - 如何正确地将 Kmeans 标签转换为类别标签