C # analog keyboard input (1 ),

Source: Internet
Author: User

C # analog keyboard input (1 ),

The Windows API is used for implementation. You can find user32.dll In the system32 folder on your drive C. The function description is available in MSDN. You only need to search the user32.dll by name.

Obtain the window handle based on the class name and window name of the window. A Window handle is returned successfully. Otherwise, 0 is returned:

        [DllImport("User32.dll", EntryPoint = "FindWindow")]        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

Find the first subwindow that matches the specified condition in the window list.

        [DllImport("user32.dll", EntryPoint = "FindWindowEx")]        static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClass, string lpszWindow);

Find the handle and send a message to the window. The SendMessage method has many reloads.

        [DllImport("user32.dll ", EntryPoint = "SendMessage")]        public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);        [DllImport("user32.dll", EntryPoint = "SendMessage")]        public static extern IntPtr SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);
Const int WM_CHAR = 0x0102; const int WM_SETTEXT = 0x000C; const int VK_RETURN = 0x0d; static void Main (string [] args) {IntPtr handle = FindWindow (null, "Hello.txt-Notepad"); handle = find+wex (handle, IntPtr. zero, "Edit", null); if (handle = IntPtr. zero) {Console. writeLine ("no handle found"); return;} SendMessage (handle, WM_SETTEXT, IntPtr. zero, "Hello word! ");
SendMessage (handle, WM_CHAR, (IntPtr) VK_RETURN, IntPtr. Zero); // Enter
}

Related links:

Virtual key table: http://baike.baidu.com/view/555571.htm

SendMessage type: http://baike.baidu.com/view/1080187.htm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.