【问题标题】:Sending keys to inactive application in C#/.NET [duplicate]将密钥发送到 C#/.NET 中的非活动应用程序 [重复]
【发布时间】:2009-10-18 12:30:28
【问题描述】:

我有一个带有组合框的应用程序,其中包含当前正在运行的应用程序的名称。正如我从 msdn 库中了解到的,SendKeys 方法只能将密钥发送到活动应用程序。在.NET中是否有可能将密钥也发送到非活动应用程序?或者至少在 WinAPI 中?

【问题讨论】:

  • 不是重复的,因为它专门询问非活动应用程序

标签: c# .net sendkeys


【解决方案1】:

您可以使用SendMessage() API 函数将击键发送到非活动窗口。

【讨论】:

    【解决方案2】:

    使用 C#

    如你所愿,无需成为活动窗口。

    还有here 一个有用的虚拟键代码列表

            [DllImport("user32.dll")]
            public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    
            [DllImport("user32.dll")]
            public static extern bool PostMessage(int hWnd, uint Msg, int wParam, int lParam);
    
            private void button1_Click(object sender, EventArgs e)
            {
                const int WM_SYSKEYDOWN = 0x0104;
                const int VK_KEY_A = 0x41;
    
                IntPtr WindowToFind = FindWindow(null, "Window Name");
    
              //In ur case u have to write a code that translates the combobox into Virtual Key Codes. Will take time but it shouls be easy
    
                PostMessage(WindowToFind, WM_SYSKEYDOWN, VK_KEY_A, 0);
              //PostMessage(WindowToFind, WM_SYSKEYDOWN, ((int)Keys.NumPad7), 0);
            }
    

    【讨论】:

    • 请停止为多个问题添加相同的答案。将其添加到一个,然后标记为重复。
    • 我做到了。 Ty 提示 :)
    猜你喜欢
    • 2014-02-15
    • 1970-01-01
    • 2014-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-12
    • 2011-01-07
    • 2017-09-20
    相关资源
    最近更新 更多