Results 1 to 11 of 11

Thread: keyboard control?

  1. #1

    Thread Starter
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Public Sub Main()
    SendKeys Chr(vbKeyReturn)
    End Sub

  2. #2
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    Try the following code.
    Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    Private Const KEYEVENTF_EXTENDEDKEY = &H1
    Private Const KEYEVENTF_KEYUP = &H2

    Private Sub Form_KeyPress(KeyAscii As Integer)
    Debug.Print KeyAscii
    End Sub

    Private Sub Form_Load()
    keybd_event vbKeyReturn, 0, 0, 0

    keybd_event vbKeyReturn, 0, KEYEVENTF_KEYUP, 0

    End Sub

  3. #3

    Thread Starter
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Maybe I missed something.

    Is there a problem with mine?

  4. #4
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    No Problem !! Your code is exactly perfect
    I used to use SendKeys but on occasions i came to know that it is slow...therefore I personally prefer Keybd_Event....Nothing ELSE...

  5. #5
    New Member
    Join Date
    Mar 2002
    Posts
    3
    thanks for the quick response.....


    it works perfect.



    steve

  6. #6

    Thread Starter
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    OK, cool. I'll keep that in mind.

  7. #7
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    Oops!! I forgot.....
    Keybd_Event is capable of simulating key downs of keys..(I am not sure but I think SendKeys cannot send extended keys(Alt,Ctrl )through their virtual key codes, correct me if i am wrong) and it can also send extra information about the keys....therefore it is more than a function which just simulates the key presses....

  8. #8

    Thread Starter
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Yes, it can simulate a key being held down, whereas SendKeys cannot.

    However, he only asked for a return press.

    Your example appeared somewhat like taking a BFG in to kill one drone (pardon the comparison).

    However, it still gets the job done, which is the most important part.

  9. #9
    Member Manor39's Avatar
    Join Date
    Mar 2002
    Location
    Cambridgeshire
    Posts
    38
    I used SendKey in a prog I wrote in W2KPro and it flew. I ran the program in my Win95 partition and it ran like treacle.

    I may try the keybd_event to allow better backward OS compatibility.
    Regards
    John Pike

    There are never any problems, just challenges.

  10. #10
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    Lord_Rat, please stop being simple. You know the right answer is always the most complicated one. We expect immediate improvement lest you be shunned from the island.

    Thank you.

  11. #11

    Thread Starter
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    *slaps forehead

    OK .. ... .. ok

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width