Results 1 to 4 of 4

Thread: Let's reopen the keyboard/focus can of worms...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    dev/null
    Posts
    64

    Exclamation Let's reopen the keyboard/focus can of worms...

    A slightly different perspective on this one, tho. Barring the global hooks/memory eat-up/slow OS death spiral that left me quite confused (and Windows quite pissed off at me too, I might add)...I was wondering this.

    It keeps being hinted at in the documentation I've been poring over that there's a way to get keystroke information directly from the keyboard's driver, which would seem to bypass the whole mess mentioned above, but I can't seem to find anything else about it. Is this just a pipe dream, or is there some way of doing this through the API...?

  2. #2
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    I missed the original can of worms...what information do you want to get from the keyboard driver?

    If it is just a system wide keyboard hook I have a simple example here that may be of interest.

    HTH,
    Duncan

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Here is a example that I think might get you going, and its not too messy.
    VB Code:
    1. Const VK_H = 72
    2. Const VK_E = 69
    3. Const VK_L = 76
    4. Const VK_O = 79
    5. Const KEYEVENTF_EXTENDEDKEY = &H1
    6. Const KEYEVENTF_KEYUP = &H2
    7. Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    8. Private Sub Form_KeyPress(KeyAscii As Integer)
    9.     'Print the key on the form
    10.     Me.Print Chr$(KeyAscii);
    11. End Sub
    12. Private Sub Form_Paint()
    13.     'KPD-Team 2000
    14.     'URL: [url]http://www.allapi.net/[/url]
    15.     'E-Mail: [email][email protected][/email]
    16.     'Clear the form
    17.     Me.Cls
    18.     keybd_event VK_H, 0, 0, 0   ' press H
    19.     keybd_event VK_H, 0, KEYEVENTF_KEYUP, 0   ' release H
    20.     keybd_event VK_E, 0, 0, 0  ' press E
    21.     keybd_event VK_E, 0, KEYEVENTF_KEYUP, 0  ' release E
    22.     keybd_event VK_L, 0, 0, 0  ' press L
    23.     keybd_event VK_L, 0, KEYEVENTF_KEYUP, 0  ' release L
    24.     keybd_event VK_L, 0, 0, 0  ' press L
    25.     keybd_event VK_L, 0, KEYEVENTF_KEYUP, 0  ' release L
    26.     keybd_event VK_O, 0, 0, 0  ' press O
    27.     keybd_event VK_O, 0, KEYEVENTF_KEYUP, 0  ' release O
    28. End Sub
    The keybd_event function synthesizes a keystroke. The system can use such a synthesized keystroke to generate a WM_KEYUP or WM_KEYDOWN message. The keyboard driver’s interrupt handler calls the keybd_event function.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    dev/null
    Posts
    64
    Well, the original can of worms (which is now buried in the depths of the board) was discussing ways to have VB programs receive keystrokes even when its form didn't have the focus.

    One way which was discussed was to create a DLL that held a global hook to capture keystrokes from all processes...but the end result (it seems) was some serious system slowdown, as every process had to load the pointer to the DLL and pass it the information.

    On the other hand, it seems that it might be possible to simply (hah!) have VB talk directly to the device driver itself, getting a copy of the keyboard input as they are passed from the driver into Windows, and thus being able to respond without having the focus...which is what I'm trying to figure out.

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