C# // SendKeys.SendWait works only when process'es window is minimzed

后端 未结 1 1034
夕颜
夕颜 2020-12-17 03:07
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.ComponentModel;
using System.Data;
using         


        
相关标签:
1条回答
  • 2020-12-17 04:03

    Try using the SetForegroundWindow Win32 API call, instead of ShowWindow, to activate the game window. (Signature from pinvoke.net.)

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool SetForegroundWindow(IntPtr hWnd);
    
    static void Main(string[] args)
    {
        Process[] processes = Process.GetProcessesByName("game");
        Process game1 = processes[0];
    
        IntPtr p = game1.MainWindowHandle;
    
        SetForegroundWindow(p);
        SendKeys.SendWait("{DOWN}");
        Thread.Sleep(1000);
        SendKeys.SendWait("{DOWN}");
    }
    
    0 讨论(0)
提交回复
热议问题