Results 1 to 19 of 19

Thread: Capture Key Strokes of Windows

Threaded View

  1. #11
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Smile

    OK, going with what i said earlier, i did some research and found out that you can actually use the GetAsyncKeyState function shown above to determine the status of the mouse buttons. The Virtual Keys are:
    VK_LBUTTON (&H01)
    VK_RBUTTON (&H02)
    VK_MBUTTON (&H04)
    And If your mouse buttons are swapped, it doesn't make
    any difference to the function. It detects the actual buttons themselves. Hope this helps.
    If you are interested in recording every keystroke, your program might benefit from this subroutine:

    Declare Function GetKeyboardState Lib "user32" _(pbKeyState As Byte) As Long
    Private Sub Timer1_timer()
    Dim keyarray(256) As Byte
    dim dl
    dl& = GetKeyboardState(keyarray(0))
    control% = keyarray(vbKeyControl)
    b% =keyarray(vbKeyB)
    if (control% AND 128) = TRUE And (B% AND 128) = _
    TRUE then msgbox "You pressed ctrl-b"

    Virtual key codes work like indexes to the array. Bit one
    of each index is "on" or "off" for toggle keys like caps lock. Bit 7 is 1 or 0 depending on if a button was pressed when the snapshot was taken.
    So you could have just one API call to "snapshot" the
    keyboard button status. This method is superior because of the time involved. Someone might have pressed ctrl-b (or whatever) and while you are processing the ctrl request using getasynckeystate, they might no longer have b pressed. My method insures you can tell they were both pressed at the same time.
    If you want to actually INTERCEPT keyboard messages meant for an application and then prevent them from reaching that application, you would have to use some form of subclassing .dll or .ocx, since a vb program can only subclass itself. Since windows messages are sent to the top level window and trickle down to the child window that needs the message, i would guess that (if its possible) you would need to subclass the message handler of the desktop. If windows won't let you, you would need to subclass the message handler of each parent window open. Unless there is a specific application that you had in mind.
    Last edited by Lord Orwell; Feb 10th, 2001 at 10:26 PM.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

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