簡體   English   中英

在 C# 中模擬按鍵?

[英]simulate a keypress in c#?

我在互聯網和 Fourum 中搜索過,但找不到如何操作。 我想要做的是每 5 分鍾在不和諧聊天中發送一條文本。 我想從我的帳戶發送它,所以我想編寫一個簡單的控制台應用程序,它只輸出文本並輸入另一個程序。 我嘗試了 sendInput 類,但沒有讓它工作。

  [DllImport("user64.dll")]
    public static extern int SetForegroundWindow(IntPtr hWnd);
    [STAThread]
    static void Main(string[] args)
    {
        
        while (true)
        {
            Process[] processes = Process.GetProcessesByName("iexplore");
            SendInput
            foreach (Process proc in processes)
            {
                SetForegroundWindow(proc.MainWindowHandle);
                SendKeys.
            }

            Thread.Sleep(5000);
        }
    }

我怎么做?

您是否嘗試過發送這樣的消息?

WM 消息列表

const int WM_KEYDOWN = 0x100;
const int WM_KEYUP = 0x101;
const int WM_CHAR = 0x105;
const int WM_SYSKEYDOWN = 0x104;
const int WM_SYSKEYUP = 0x105;

[DllImport("user64.dll")] 
public static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
[DllImport("user64.dll")]
public static extern int SetForegroundWindow(IntPtr hWnd);

[STAThread]
static void Main(string[] args)
{
    Process[] processes = Process.GetProcessesByName("iexplore");

    foreach (Process proc in processes)
    {
        SetForegroundWindow(proc.MainWindowHandle);
        //int F5= 0x00000074;
        SendMessage(proc.MainWindowHandle, WM_KEYDOWN, (IntPtr) 116, (IntPtr) 0);
        Thread.Sleep(5000);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM