How to write a keyboard event to a specified program window with VB

Updated on technology 2024-02-28
5 answers
  1. Anonymous users2024-02-06

    The following methods are for reference.

    Method 1: Use the sendkeys statement.

    sendkeys "a", true 'Send the character a

    Method 2: Use API functions.

    This method is more complicated to implement, and gives you an idea:

    Use FindWindow to find a window with a specific title, get a handle to that window, and send a keyboard message to that window with SendMessage.

    declare function findwindow lib "user32" alias "findwindowa" (byval lpclassname as string, byval lpwindowname as string) as long

    declare function sendmessage lib "user32" alias "sendmessagea" (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any) as long

  2. Anonymous users2024-02-05

    Build a command1. I'll take a calculator as an example. **As follows.

    private sub command1_click()dim t as long

    t = shell("calc")

    sendkeys "123"

    end sub

  3. Anonymous users2024-02-04

    Here's how to execute a keyboard event:

    The first step is to click on vs tools.

    The second step, after opening, create a new Windows Forms application.

    The third step is to look at the property bar of the form at the bottom right.

    Step 4: Double-click the keydown.

    <> step 6, enter ** again and set the attribute keypreview to true.

    Step 7: Run the program, press the example F5, and a prompt will pop up to indicate that it has been successfully obtained.

  4. Anonymous users2024-02-03

    1. First of all, double-click the blank space of the form to enter the ** window.

    2. Then we find the click event in the event.

    3. At this time, start writing a test [print]."I'm clicking on the property! "】。

    4. Then we start running the test.

    5. After launching, we click on the blank space of the form.

    6. At this time, we will see the effect of the test.

  5. Anonymous users2024-02-02

    option explicit

    private sub command1_click()print

    end sub

    private sub form_load()text1 = "Question: How to write in VB Click the command button, and the form will display the content in the text box? "

    end sub

Related questions
6 answers2024-02-28

I tried going downstairs with no problem. If it can't be opened, the landlord can try this sentence: (note that it is 3 quotation marks). >>>More

6 answers2024-02-28

Good question, write with a for loop and judgment statement. >>>More

6 answers2024-02-28

The second line declares that the textbox control array ** is wrong and does not conform to the syntax specification! >>>More

8 answers2024-02-28

Error file, basically useless, so don't open it.

3 answers2024-02-28

If you want the source**, I can make one and send it to you. >>>More