Sending keys to inactive application in C#/.NET [duplicate]

喜你入骨 提交于 2019-12-02 02:08:06

You can use the SendMessage() API function to send keystrokes to an inactive window.

With C# <3 is everthing possible :D

No need to be active window, as u wished.

Also here a usefull list of Virtual Key Codes

        [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);
        }
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!