Results 1 to 6 of 6

Thread: Sample Code for Logging all keypresses?

  1. #1

    Thread Starter
    Junior Member SkettaLEE's Avatar
    Join Date
    Oct 2001
    Location
    Shaw AFB, SC
    Posts
    30

    Sample Code for Logging all keypresses?

    Does anyone have a sample code for logging which keys are pressed on the computer?
    This is our world now, The world of the pop-trunk and the switch.
    The beauty of my Broad :-)
    We wage wars, murder, cheat, lie to our women and make them believe its for their own good. And we're the criminals.
    My crime is but of pimpology.
    I am a Pimp, and this is my manefesto!

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    You need to be more specific in your request. On the face of this
    Does anyone have a sample code for logging which keys are pressed on the computer?
    I'm thinking that you want code to write a program that will capture every key pressed, in any program (i.e., Word, Excel, Internet Explorer, all games, in short, any software installed on the machine, or that ever will be installed on the machine). I suspect that you have a more specific intent. What exactly do you wish to do, and in what/or where would you like to do it?

  3. #3
    Hyperactive Member
    Join Date
    Oct 2001
    Location
    The Netherlands
    Posts
    403
    I've done it before by searching for the window with focus, then subclass it (don't forget to send the messages you get to the window too ). You will now receive all keypresses for that window. If you check when it loses focus you can find the window that haves focus now, subclass it....

    But a second way could be checking the getkeyboardstate API function. put it in a timer or something (not my favorite way).
    This ain't the best way to do it, you are probebly looking for a event that passes the keycode or something. I don't know one, but if someone doese, it'll be greatly appreceited by me too.

  4. #4
    New Member
    Join Date
    Sep 2001
    Location
    clonk planet
    Posts
    2
    You are looking for so-called 'system wide hook'. It's is not possible from VB, but you can use DLL written in C or ASM. Look on the net for one.

  5. #5
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    Yes it is possible from VB....look here....

    http://forums.vb-world.net/showthrea...hlight=crispin
    Crispin
    VB6 ENT SP5
    VB.NET
    W2K ADV SVR SP3
    WWW.BLOCKSOFT.CO.UK

    [Microsoft Basic: 1976-2001, RIP]

  6. #6
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    VB Code:
    1. 'in form
    2. Private Sub Form_Load()
    3. Hook
    4.  
    5. End Sub
    6.  
    7. Private Sub Form_Unload(Cancel As Integer)
    8. UnHook
    9.  
    10. End Sub
    11.  
    12. 'in module
    13. Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
    14. Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
    15. Public Const WH_KEYBOARD = 2
    16. Dim lpPrevProc As Long
    17. Sub Hook()
    18. lpPrevProc = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, 0, 0)
    19. End Sub
    20. Sub UnHook()
    21. UnhookWindowsHookEx lpPrevProc
    22. End Sub
    23. Function KeyboardProc(ByVal code As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    24. Debug.Print code & ":" & wParam & ":" & lParam
    25. End Function

    That's as much as I have written for my little proggie

    Have a look here:
    http://www.vbforums.com/showthread.p...setwindowshook

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