diff --git a/GenshinBalladsOfBreezeAider/GenshinBalladsOfBreezeAider.csproj b/GenshinBalladsOfBreezeAider/GenshinBalladsOfBreezeAider.csproj index c6f2a19..a4f7384 100644 --- a/GenshinBalladsOfBreezeAider/GenshinBalladsOfBreezeAider.csproj +++ b/GenshinBalladsOfBreezeAider/GenshinBalladsOfBreezeAider.csproj @@ -35,6 +35,7 @@ + @@ -54,6 +55,10 @@ + + + frmMain.cs + ResXFileCodeGenerator Resources.Designer.cs diff --git a/GenshinBalladsOfBreezeAider/WinIO32.cs b/GenshinBalladsOfBreezeAider/WinIO32.cs new file mode 100644 index 0000000..ef391ff --- /dev/null +++ b/GenshinBalladsOfBreezeAider/WinIO32.cs @@ -0,0 +1,215 @@ +using System; +using System.Runtime.InteropServices; + +namespace GenshinBalladsOfBreezeAider +{ + public static class WinIo + { + public const int KBC_KEY_CMD = 0x64; + public const int KBC_KEY_DATA = 0x60; + [DllImport("winio.dll")] + public static extern bool InitializeWinIo(); + [DllImport("winio.dll")] + public static extern bool GetPortVal(IntPtr wPortAddr, out int pdwPortVal, byte bSize); + [DllImport("winio.dll")] + public static extern bool SetPortVal(uint wPortAddr, IntPtr dwPortVal, byte bSize); + [DllImport("winio.dll")] + public static extern byte MapPhysToLin(byte pbPhysAddr, uint dwPhysSize, IntPtr PhysicalMemoryHandle); + [DllImport("winio.dll")] + public static extern bool UnmapPhysicalMemory(IntPtr PhysicalMemoryHandle, byte pbLinAddr); + [DllImport("winio.dll")] + public static extern bool GetPhysLong(IntPtr pbPhysAddr, byte pdwPhysVal); + [DllImport("winio.dll")] + public static extern bool SetPhysLong(IntPtr pbPhysAddr, byte dwPhysVal); + [DllImport("winio.dll")] + public static extern void ShutdownWinIo(); + [DllImport("user32.dll")] + public static extern int MapVirtualKey(uint Ucode, uint uMapType); + + public static void sendwinio() + { + if (InitializeWinIo()) + { + KBCWait4IBE(); + } + + } + ///Wait for Buffer gets empty + private static void KBCWait4IBE() + { + int dwVal = 0; + do + { + bool flag = GetPortVal((IntPtr)0x64, out dwVal, 1); + } + while ((dwVal & 0x2) > 0); + } + /// key down + public static void MykeyDown(int vKeyCoad) + { + int btScancode = 0; + btScancode = MapVirtualKey((byte)vKeyCoad, 0); + KBCWait4IBE(); + SetPortVal(KBC_KEY_CMD, (IntPtr)0xD2, 1); + KBCWait4IBE(); + SetPortVal(KBC_KEY_DATA, (IntPtr)0xe2, 1); + KBCWait4IBE(); + SetPortVal(KBC_KEY_CMD, (IntPtr)0xD2, 1); + KBCWait4IBE(); + SetPortVal(KBC_KEY_DATA, (IntPtr)btScancode, 1); + } + /// Key up + public static void MykeyUp(int vKeyCoad) + { + int btScancode = 0; + btScancode = MapVirtualKey((byte)vKeyCoad, 0); + KBCWait4IBE(); + SetPortVal(KBC_KEY_CMD, (IntPtr)0xD2, 1); + KBCWait4IBE(); + SetPortVal(KBC_KEY_DATA, (IntPtr)0xe0, 1); + KBCWait4IBE(); + SetPortVal(KBC_KEY_CMD, (IntPtr)0xD2, 1); + KBCWait4IBE(); + SetPortVal(KBC_KEY_DATA, (IntPtr)btScancode, 1); + } + /// Simulate mouse down + public static void MyMouseDown(int vKeyCoad) + { + int btScancode = 0; + btScancode = MapVirtualKey((byte)vKeyCoad, 0); + KBCWait4IBE(); // 'wait for buffer gets empty + SetPortVal(KBC_KEY_CMD, (IntPtr)0xD3, 1);// 'send write command + KBCWait4IBE(); + SetPortVal(KBC_KEY_DATA, (IntPtr)(btScancode | 0x80), 1);// 'write in io + } + /// Simulate mouse up + public static void MyMouseUp(int vKeyCoad) + { + int btScancode = 0; + btScancode = MapVirtualKey((byte)vKeyCoad, 0); + KBCWait4IBE(); // 'wait for buffer gets empty + SetPortVal(KBC_KEY_CMD, (IntPtr)0xD3, 1); //'send write command + KBCWait4IBE(); + SetPortVal(KBC_KEY_DATA, (IntPtr)(btScancode | 0x80), 1);// 'write in io + } + + + //---------------------------------------------------------------------------------- + //VK codes + //---------------------------------------------------------------------------------- + public enum Key + { + // mouse movements + move = 0x0001, + leftdown = 0x0002, + leftup = 0x0004, + rightdown = 0x0008, + rightup = 0x0010, + middledown = 0x0020, + //keyboard stuff + VK_LBUTTON = 1, + VK_RBUTTON = 2, + VK_CANCEL = 3, + VK_MBUTTON = 4, + VK_BACK = 8, + VK_TAB = 9, + VK_CLEAR = 12, + VK_RETURN = 13, + VK_SHIFT = 16, + VK_CONTROL = 17, + VK_MENU = 18, + VK_PAUSE = 19, + VK_CAPITAL = 20, + VK_ESCAPE = 27, + VK_SPACE = 32, + VK_PRIOR = 33, + VK_NEXT = 34, + VK_END = 35, + VK_HOME = 36, + VK_LEFT = 37, + VK_UP = 38, + VK_RIGHT = 39, + VK_DOWN = 40, + VK_SELECT = 41, + VK_PRINT = 42, + VK_EXECUTE = 43, + VK_SNAPSHOT = 44, + VK_INSERT = 45, + VK_DELETE = 46, + VK_HELP = 47, + VK_NUM0 = 48, //0 + VK_NUM1 = 49, //1 + VK_NUM2 = 50, //2 + VK_NUM3 = 51, //3 + VK_NUM4 = 52, //4 + VK_NUM5 = 53, //5 + VK_NUM6 = 54, //6 + VK_NUM7 = 55, //7 + VK_NUM8 = 56, //8 + VK_NUM9 = 57, //9 + VK_A = 65, //A + VK_B = 66, //B + VK_C = 67, //C + VK_D = 68, //D + VK_E = 69, //E + VK_F = 70, //F + VK_G = 71, //G + VK_H = 72, //H + VK_I = 73, //I + VK_J = 74, //J + VK_K = 75, //K + VK_L = 76, //L + VK_M = 77, //M + VK_N = 78, //N + VK_O = 79, //O + VK_P = 80, //P + VK_Q = 81, //Q + VK_R = 82, //R + VK_S = 83, //S + VK_T = 84, //T + VK_U = 85, //U + VK_V = 86, //V + VK_W = 87, //W + VK_X = 88, //X + VK_Y = 89, //Y + VK_Z = 90, //Z + VK_NUMPAD0 = 96, //0 + VK_NUMPAD1 = 97, //1 + VK_NUMPAD2 = 98, //2 + VK_NUMPAD3 = 99, //3 + VK_NUMPAD4 = 100, //4 + VK_NUMPAD5 = 101, //5 + VK_NUMPAD6 = 102, //6 + VK_NUMPAD7 = 103, //7 + VK_NUMPAD8 = 104, //8 + VK_NUMPAD9 = 105, //9 + VK_NULTIPLY = 106, + VK_ADD = 107, + VK_SEPARATOR = 108, + VK_SUBTRACT = 109, + VK_DECIMAL = 110, + VK_DIVIDE = 111, + VK_F1 = 112, + VK_F2 = 113, + VK_F3 = 114, + VK_F4 = 115, + VK_F5 = 116, + VK_F6 = 117, + VK_F7 = 118, + VK_F8 = 119, + VK_F9 = 120, + VK_F10 = 121, + VK_F11 = 122, + VK_F12 = 123, + VK_NUMLOCK = 144, + VK_SCROLL = 145, + middleup = 0x0040, + xdown = 0x0080, + xup = 0x0100, + wheel = 0x0800, + virtualdesk = 0x4000, + absolute = 0x8000 + } + } + +} diff --git a/GenshinBalladsOfBreezeAider/frmMain.Designer.cs b/GenshinBalladsOfBreezeAider/frmMain.Designer.cs index 2170d9a..e8946ab 100644 --- a/GenshinBalladsOfBreezeAider/frmMain.Designer.cs +++ b/GenshinBalladsOfBreezeAider/frmMain.Designer.cs @@ -39,15 +39,17 @@ private void InitializeComponent() this.lblWindowLocationTitle = new System.Windows.Forms.Label(); this.lblWindowType = new System.Windows.Forms.Label(); this.lblWindowTypeTitle = new System.Windows.Forms.Label(); + this.debugTextBox = new System.Windows.Forms.TextBox(); this.groupGenshinProcess.SuspendLayout(); this.SuspendLayout(); // // btnStart // this.btnStart.Enabled = false; - this.btnStart.Location = new System.Drawing.Point(121, 174); + this.btnStart.Location = new System.Drawing.Point(161, 218); + this.btnStart.Margin = new System.Windows.Forms.Padding(4); this.btnStart.Name = "btnStart"; - this.btnStart.Size = new System.Drawing.Size(100, 30); + this.btnStart.Size = new System.Drawing.Size(133, 38); this.btnStart.TabIndex = 0; this.btnStart.Text = "开始自动演奏"; this.btnStart.UseVisualStyleBackColor = true; @@ -57,18 +59,20 @@ private void InitializeComponent() // this.lblStatus.AutoSize = true; this.lblStatus.ForeColor = System.Drawing.Color.Red; - this.lblStatus.Location = new System.Drawing.Point(120, 23); + this.lblStatus.Location = new System.Drawing.Point(160, 29); + this.lblStatus.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lblStatus.Name = "lblStatus"; - this.lblStatus.Size = new System.Drawing.Size(89, 12); + this.lblStatus.Size = new System.Drawing.Size(112, 15); this.lblStatus.TabIndex = 1; this.lblStatus.Text = "未找到原神进程"; // // lblStatusTitle // this.lblStatusTitle.AutoSize = true; - this.lblStatusTitle.Location = new System.Drawing.Point(49, 23); + this.lblStatusTitle.Location = new System.Drawing.Point(65, 29); + this.lblStatusTitle.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lblStatusTitle.Name = "lblStatusTitle"; - this.lblStatusTitle.Size = new System.Drawing.Size(65, 12); + this.lblStatusTitle.Size = new System.Drawing.Size(82, 15); this.lblStatusTitle.TabIndex = 2; this.lblStatusTitle.Text = "程序状态:"; // @@ -80,9 +84,11 @@ private void InitializeComponent() this.groupGenshinProcess.Controls.Add(this.lblWindowLocationTitle); this.groupGenshinProcess.Controls.Add(this.lblWindowType); this.groupGenshinProcess.Controls.Add(this.lblWindowTypeTitle); - this.groupGenshinProcess.Location = new System.Drawing.Point(22, 53); + this.groupGenshinProcess.Location = new System.Drawing.Point(29, 66); + this.groupGenshinProcess.Margin = new System.Windows.Forms.Padding(4); this.groupGenshinProcess.Name = "groupGenshinProcess"; - this.groupGenshinProcess.Size = new System.Drawing.Size(297, 101); + this.groupGenshinProcess.Padding = new System.Windows.Forms.Padding(4); + this.groupGenshinProcess.Size = new System.Drawing.Size(396, 126); this.groupGenshinProcess.TabIndex = 4; this.groupGenshinProcess.TabStop = false; this.groupGenshinProcess.Text = "原神窗口信息"; @@ -90,66 +96,86 @@ private void InitializeComponent() // lblWindowSize // this.lblWindowSize.AutoSize = true; - this.lblWindowSize.Location = new System.Drawing.Point(112, 71); + this.lblWindowSize.Location = new System.Drawing.Point(149, 89); + this.lblWindowSize.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lblWindowSize.Name = "lblWindowSize"; - this.lblWindowSize.Size = new System.Drawing.Size(29, 12); + this.lblWindowSize.Size = new System.Drawing.Size(37, 15); this.lblWindowSize.TabIndex = 0; this.lblWindowSize.Text = "未知"; // // lblWindowSizeTitle // this.lblWindowSizeTitle.AutoSize = true; - this.lblWindowSizeTitle.Location = new System.Drawing.Point(6, 71); + this.lblWindowSizeTitle.Location = new System.Drawing.Point(8, 89); + this.lblWindowSizeTitle.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lblWindowSizeTitle.Name = "lblWindowSizeTitle"; - this.lblWindowSizeTitle.Size = new System.Drawing.Size(53, 12); + this.lblWindowSizeTitle.Size = new System.Drawing.Size(67, 15); this.lblWindowSizeTitle.TabIndex = 0; this.lblWindowSizeTitle.Text = "分辨率:"; // // lblWindowLocation // this.lblWindowLocation.AutoSize = true; - this.lblWindowLocation.Location = new System.Drawing.Point(112, 46); + this.lblWindowLocation.Location = new System.Drawing.Point(149, 58); + this.lblWindowLocation.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lblWindowLocation.Name = "lblWindowLocation"; - this.lblWindowLocation.Size = new System.Drawing.Size(29, 12); + this.lblWindowLocation.Size = new System.Drawing.Size(37, 15); this.lblWindowLocation.TabIndex = 0; this.lblWindowLocation.Text = "未知"; // // lblWindowLocationTitle // this.lblWindowLocationTitle.AutoSize = true; - this.lblWindowLocationTitle.Location = new System.Drawing.Point(6, 46); + this.lblWindowLocationTitle.Location = new System.Drawing.Point(8, 58); + this.lblWindowLocationTitle.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lblWindowLocationTitle.Name = "lblWindowLocationTitle"; - this.lblWindowLocationTitle.Size = new System.Drawing.Size(77, 12); + this.lblWindowLocationTitle.Size = new System.Drawing.Size(97, 15); this.lblWindowLocationTitle.TabIndex = 0; this.lblWindowLocationTitle.Text = "左上角坐标:"; // // lblWindowType // this.lblWindowType.AutoSize = true; - this.lblWindowType.Location = new System.Drawing.Point(112, 21); + this.lblWindowType.Location = new System.Drawing.Point(149, 26); + this.lblWindowType.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lblWindowType.Name = "lblWindowType"; - this.lblWindowType.Size = new System.Drawing.Size(29, 12); + this.lblWindowType.Size = new System.Drawing.Size(37, 15); this.lblWindowType.TabIndex = 0; this.lblWindowType.Text = "未知"; // // lblWindowTypeTitle // this.lblWindowTypeTitle.AutoSize = true; - this.lblWindowTypeTitle.Location = new System.Drawing.Point(7, 21); + this.lblWindowTypeTitle.Location = new System.Drawing.Point(9, 26); + this.lblWindowTypeTitle.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); this.lblWindowTypeTitle.Name = "lblWindowTypeTitle"; - this.lblWindowTypeTitle.Size = new System.Drawing.Size(65, 12); + this.lblWindowTypeTitle.Size = new System.Drawing.Size(82, 15); this.lblWindowTypeTitle.TabIndex = 0; this.lblWindowTypeTitle.Text = "窗口状态:"; // + // debugTextBox + // + this.debugTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.debugTextBox.Location = new System.Drawing.Point(12, 263); + this.debugTextBox.Multiline = true; + this.debugTextBox.Name = "debugTextBox"; + this.debugTextBox.Size = new System.Drawing.Size(433, 0); + this.debugTextBox.TabIndex = 5; + this.debugTextBox.Visible = false; + // // frmMain // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(343, 216); + this.ClientSize = new System.Drawing.Size(457, 267); + this.Controls.Add(this.debugTextBox); this.Controls.Add(this.groupGenshinProcess); this.Controls.Add(this.lblStatusTitle); this.Controls.Add(this.lblStatus); this.Controls.Add(this.btnStart); + this.Margin = new System.Windows.Forms.Padding(4); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "frmMain"; @@ -173,6 +199,7 @@ private void InitializeComponent() private System.Windows.Forms.Label lblWindowLocationTitle; private System.Windows.Forms.Label lblWindowType; private System.Windows.Forms.Label lblWindowTypeTitle; + private System.Windows.Forms.TextBox debugTextBox; } } diff --git a/GenshinBalladsOfBreezeAider/frmMain.cs b/GenshinBalladsOfBreezeAider/frmMain.cs index a41e013..c49d1aa 100644 --- a/GenshinBalladsOfBreezeAider/frmMain.cs +++ b/GenshinBalladsOfBreezeAider/frmMain.cs @@ -1,5 +1,6 @@ using System; using System.Drawing; +using System.Management; using System.Runtime.InteropServices; using System.Threading.Tasks; using System.Windows.Forms; @@ -18,10 +19,23 @@ public partial class frmMain : Form private static extern int GetWindowRect(IntPtr hwnd, out Rectangle lpRect); [DllImport("user32.dll")] - public static extern bool GetClientRect(IntPtr hwnd, out Rectangle lpRect); + private static extern bool GetClientRect(IntPtr hwnd, out Rectangle lpRect); [DllImport("user32")] - public static extern int GetSystemMetrics(int nIndex); + private static extern int GetSystemMetrics(int nIndex); + + + [DllImport("user32.dll")] + private static extern IntPtr GetDC(IntPtr ptr); + [DllImport("gdi32.dll")] + private static extern int GetDeviceCaps(IntPtr hdc, int nIndex); + [DllImport("user32.dll", EntryPoint = "ReleaseDC")] + private static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc); + + const int HORZRES = 8; + const int VERTRES = 10; + const int DESKTOPVERTRES = 117; + const int DESKTOPHORZRES = 118; private IntPtr hwndGenshin = IntPtr.Zero; @@ -31,6 +45,28 @@ public partial class frmMain : Form private int genshinWindowHeight = 0; private bool working = false; + public static float DpiScaleX + { + get + { + IntPtr hdc = GetDC(IntPtr.Zero); + float ScaleX = (float)GetDeviceCaps(hdc, DESKTOPHORZRES) / (float)GetDeviceCaps(hdc, HORZRES); + ReleaseDC(IntPtr.Zero, hdc); + return ScaleX; + } + } + + public static float DpiScaleY + { + get + { + IntPtr hdc = GetDC(IntPtr.Zero); + float ScaleY = (float)(float)GetDeviceCaps(hdc, DESKTOPVERTRES) / (float)GetDeviceCaps(hdc, VERTRES); + ReleaseDC(IntPtr.Zero, hdc); + return ScaleY; + } + } + public frmMain() => InitializeComponent(); protected override void OnShown(EventArgs e) @@ -52,6 +88,7 @@ private void FindGenshinProcess() hwndGenshin = FindWindow("UnityWndClass", "原神"); Task.Delay(100).Wait(); } + GetWindowRect(hwndGenshin, out Rectangle windowRect); GetClientRect(hwndGenshin, out Rectangle clientRect); @@ -64,30 +101,40 @@ private void FindGenshinProcess() lblStatus.Text = $"已找到原神进程,未开始自动演奏"; lblStatus.ForeColor = Color.Black; } + + float dpiX = DpiScaleX; + float dpiY = DpiScaleY; + if (windowRect.X < -16000) //全屏 { genshinWindowX = 0; genshinWindowY = 0; - genshinWindowWdith = Screen.PrimaryScreen.Bounds.Width; - genshinWindowHeight = Screen.PrimaryScreen.Bounds.Height; + genshinWindowWdith = (int)Math.Round(Screen.PrimaryScreen.Bounds.Width * dpiX); + genshinWindowHeight = (int)Math.Round(Screen.PrimaryScreen.Bounds.Height * DpiScaleY); lblWindowType.Text = "全屏"; lblWindowLocation.Text = $"(0,0)"; - lblWindowSize.Text = $"{Screen.PrimaryScreen.Bounds.Width}×{Screen.PrimaryScreen.Bounds.Height}"; + lblWindowSize.Text = $"{genshinWindowWdith}×{genshinWindowHeight}"; } else //窗口化 { Rectangle tempRect = new Rectangle(windowRect.X, windowRect.Y, windowRect.Width - windowRect.X, windowRect.Height - windowRect.Y); Rectangle rect = new Rectangle(tempRect.X + (tempRect.Width - clientRect.Width) - 3, tempRect.Y + (tempRect.Height - clientRect.Height) - 3, clientRect.Width, clientRect.Height); - lblWindowType.Text = "窗口化"; - lblWindowLocation.Text = $"({rect.X},{rect.Y})"; - lblWindowSize.Text = $"{rect.Width}×{rect.Height}"; + if (dpiX > 1 || DpiScaleY > 1) + { + rect = new Rectangle((int)Math.Round(rect.X * dpiX), (int)Math.Round(rect.Y * dpiY), (int)Math.Round(rect.Width * dpiX), (int)Math.Round(rect.Height * dpiY)); + } genshinWindowX = rect.X; genshinWindowY = rect.Y; genshinWindowWdith = rect.Width; genshinWindowHeight = rect.Height; + + lblWindowType.Text = "窗口化"; + lblWindowLocation.Text = $"({genshinWindowX},{genshinWindowY})"; + lblWindowSize.Text = $"{genshinWindowHeight}×{genshinWindowHeight}"; + } btnStart.Enabled = true; } @@ -119,10 +166,15 @@ private void btnStart_Click(object sender, EventArgs e) } Task.Run(() => { + float dpiX = DpiScaleX; + float dpiY = DpiScaleY; + while (working) { - Size s = new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); - Bitmap memoryImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); + int width = (int)Math.Round(Screen.PrimaryScreen.Bounds.Width * dpiX); + int height = (int)Math.Round(Screen.PrimaryScreen.Bounds.Height * dpiY); + Size s = new Size(width, height); + Bitmap memoryImage = new Bitmap(width, height); Graphics memoryGraphics = Graphics.FromImage(memoryImage); memoryGraphics.CopyFromScreen(0, 0, 0, 0, s); @@ -143,6 +195,44 @@ private void btnStart_Click(object sender, EventArgs e) bool wReady, sReady, aReady, dReady, iReady, kReady, jReady, lReady; + private void SaveDebugImage() + { + float dpiX = DpiScaleX; + float dpiY = DpiScaleY; + + int width = (int)Math.Round(Screen.PrimaryScreen.Bounds.Width * dpiX); + int height = (int)Math.Round(Screen.PrimaryScreen.Bounds.Height * dpiY); + Size s = new Size(width, height); + Bitmap memoryImage = new Bitmap(width, height); + Graphics memoryGraphics = Graphics.FromImage(memoryImage); + memoryGraphics.CopyFromScreen(0, 0, 0, 0, s); + + DrawDebugLine(0.253125, 0.37685, memoryImage); + DrawDebugLine(0.253125, 0.823148, memoryImage); + DrawDebugLine(0.127083, 0.6, memoryImage); + DrawDebugLine(0.378125, 0.6, memoryImage); + DrawDebugLine(0.74739583, 0.37685, memoryImage); + DrawDebugLine(0.74739583, 0.823148, memoryImage); + DrawDebugLine(0.62135416, 0.6, memoryImage); + DrawDebugLine(0.872917, 0.6, memoryImage); + + memoryImage.Save(Application.StartupPath + @"\text.jpg"); + } + + private void DrawDebugLine(double scaleX, double scaleY, Bitmap highDpiScreenshot) + { + int xw = (int)Math.Round(genshinWindowWdith * scaleX) + genshinWindowX; + int yw = (int)Math.Round(genshinWindowHeight * scaleY) + genshinWindowY; + for (int i = 0; i < highDpiScreenshot.Width; i++) + { + highDpiScreenshot.SetPixel(i, yw, Color.Red); + } + for (int i = 0; i < highDpiScreenshot.Height; i++) + { + highDpiScreenshot.SetPixel(xw, i, Color.Red); + } + } + private void StartAutoPressKey(Bitmap bmp, double scaleX, double scaleY, Keys key) { bool getReady = key switch @@ -160,7 +250,7 @@ private void StartAutoPressKey(Bitmap bmp, double scaleX, double scaleY, Keys ke int x = (int)Math.Round(genshinWindowWdith * scaleX) + genshinWindowX; int y = (int)Math.Round(genshinWindowHeight * scaleY) + genshinWindowY; - PressKey(ref getReady, bmp, x, y, (byte)key); + PressKey(ref getReady, bmp, x, y, key); switch (key) { @@ -191,7 +281,20 @@ private void StartAutoPressKey(Bitmap bmp, double scaleX, double scaleY, Keys ke } } - private void PressKey(ref bool getReady, Bitmap bmp, int x, int y, byte key) + private byte GetScancode(Keys key) => key switch + { + Keys.W => Convert.ToByte("11"), + Keys.S => Convert.ToByte("1F"), + Keys.A => Convert.ToByte("1E"), + Keys.D => Convert.ToByte("20"), + Keys.I => Convert.ToByte("17"), + Keys.K => Convert.ToByte("25"), + Keys.J => Convert.ToByte("24"), + Keys.L => Convert.ToByte("26"), + _ => throw new Exception() + }; + + private void PressKey(ref bool getReady, Bitmap bmp, int x, int y, Keys key) { Color color = bmp.GetPixel(x, y); if (!getReady) @@ -205,11 +308,16 @@ private void PressKey(ref bool getReady, Bitmap bmp, int x, int y, byte key) { if (color.R == 255 && color.G > 170 && color.G < 230 && color.B > 60 && color.B < 70) { + byte byteKey = (byte)key; //getReady = false; //连击不会显示黑色圈导致判定有问题, 现只用作判断是否开始音游 - keybd_event(key, 0, 0, 0); + //byte code = GetScancode(key); + keybd_event(byteKey, 0, 0, 0); + //WinIo.MykeyDown(byteKey); + //Invoke(new Action(() => debugTextBox.AppendText($"按下按键{((Keys)key).ToString()} ----{DateTime.Now}\r\n"))); Task.Delay(50).ContinueWith(_ => { - keybd_event(key, 0, 2, 0); + keybd_event(byteKey, 0, 2, 0); + //WinIo.MykeyUp(byteKey); }); } } diff --git a/GenshinBalladsOfBreezeAider/frmMain.resx b/GenshinBalladsOfBreezeAider/frmMain.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/GenshinBalladsOfBreezeAider/frmMain.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file