Results 1 to 24 of 24

Thread: key logger/blocker/inputer

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2002
    Posts
    45

    Lightbulb key logger/blocker/inputer

    I want to make my own vb program that:

    1) Intercepts keystrockes (even when unfocused) and can put them into a log file or display on screen or whatever.

    2) Can block keys or the entire keybored from the user

    3) Can have keys inputted by the program (aka i know how to set up tcp/ip and i will be inputting it remotely)

    I know this kinda just majorly sounds like a virus, but the reason I want to do this is because I have alot of computers in my house and eventhough there are alot of programs that do this out there to download (and I have used a few of them) I thought it would be fun to make my own one that i could personalize to my own needs

  2. #2
    Member
    Join Date
    May 2002
    Location
    Manchester, UK
    Posts
    54
    Search the net (Or the forum) for 'Keyboard hook'

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2002
    Posts
    45
    i found lots of thing concerning reading and blocking keystrokes for on the application but it wasn't global (aka all applications), and i couldn't input keystrokes using code..... if someone could post a code snippet concerning all 3 of the issues above it would be greatly appreciated

  4. #4
    Stiletto
    Guest
    This answers your first issue:
    VB Code:
    1. Private Sub Form_KeyPress(KeyAscii As Integer)
    2. If KeyAscii = vbKeyReturn Then
    3.    MsgBox "User Pressed Enter"
    4.    'Code Here
    5. End If
    6. End Sub
    This is an xample on how to fnd when the user pressed a key.
    The xample is about the Enter key only, but you can do it with al; keys.

  5. #5
    Member
    Join Date
    May 2002
    Location
    Manchester, UK
    Posts
    54
    Apparently, in VB, to do a keyboard hook you need to use a DLL

  6. #6
    Stiletto
    Guest
    Or lockin all keys in the keyboard using code ...(which is damn long)

  7. #7
    Blacknight
    Guest
    I want to buld a similiar program like simoyd, only a little diffrent:
    I want a program that once u highlight text, even on the browser and press let's say ctrl+c the highlighted text will be automaticaly sent into a text box in my program. Anybody got any ideas?

  8. #8

    Thread Starter
    Member
    Join Date
    Jan 2002
    Posts
    45
    Originally posted by Stiletto
    Or lockin all keys in the keyboard using code ...(which is damn long)
    how would i do that (I have time.... and patience..)

    or does anyone know where i can get a dll thing like the one stated above??

  9. #9
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    the apiguide example
    VB Code:
    1. 'In a module
    2. Public Const WH_KEYBOARD = 2
    3. Public Const VK_SHIFT = &H10
    4. Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
    5. Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
    6. 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
    7. Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
    8. Public hHook As Long
    9. Public Function KeyboardProc(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    10.     'if idHook is less than zero, no further processing is required
    11.     If idHook < 0 Then
    12.         'call the next hook
    13.         KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
    14.     Else
    15.         'check if SHIFT-S is pressed
    16.         If (GetKeyState(VK_SHIFT) And &HF0000000) And wParam = Asc("S") Then
    17.             'show the result
    18.             Form1.Print "Shift-S pressed ..."
    19.         End If
    20.         'call the next hook
    21.         KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
    22.     End If
    23. End Function
    24.  
    25. 'In a form, called Form1
    26. Private Sub Form_Load()
    27.     'KPD-Team 2000
    28.     'URL: [url]http://www.allapi.net/[/url]
    29.     'E-Mail: [email][email protected][/email]
    30.     'set a keyboard hook
    31.     hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, App.hInstance, App.ThreadID)
    32. End Sub
    33. Private Sub Form_Unload(Cancel As Integer)
    34.     'remove the windows-hook
    35.     UnhookWindowsHookEx hHook
    36. End Sub

    but keyboard hooking is awkward. it tells you twice of the key you pressed.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  10. #10

    Thread Starter
    Member
    Join Date
    Jan 2002
    Posts
    45
    ok... i forgot to say... i used that (or a simmilar thing) to log/read the keys (the reason that it reads it 2ce is cause it reads keyup and keydown... the example i have doesn't). I have been able to read keys and input keys... but what I want to do is also be able to block those keys... any suggestions??

  11. #11
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Originally posted by simoyd
    ok... i forgot to say... i used that (or a simmilar thing) to log/read the keys (the reason that it reads it 2ce is cause it reads keyup and keydown... the example i have doesn't). I have been able to read keys and input keys... but what I want to do is also be able to block those keys... any suggestions??
    ummm....... there are 4 when you press and release. 2 when you keydown and 2 when you keyup.

    and to block it just make sure that if it is the key you want to block dont let it get to

    KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)


    so use an exit sub before it.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  12. #12
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628
    um he stated there are a lot of programs out that do that. well windows actually comes with one. If you use Netmeeting for remote desktop sharing, it will lock out the keyboard and mouse both of the target computer and put its desktop on yours. about the only thing you can't do with it is stream mpegs (and maybe you can do that if you have a 100mpb connection; mine was 10)
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

  13. #13

    Thread Starter
    Member
    Join Date
    Jan 2002
    Posts
    45
    i know that there many programs out there.... and to my knowlage netmeeting can't block keys......

    how do i block keys?

    even if netmeeting can, i would prefer to make my own

  14. #14

    Thread Starter
    Member
    Join Date
    Jan 2002
    Posts
    45
    ^bump^

  15. #15
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    In Windows NT/2000/XP you can install a WH_KEYBOARD_LL hook (using the EventVB.dll) thus:

    VB Code:
    1. ' Form declarations
    2. Private WithEvents apiLink As EventVB.ApiFunctions
    3. Private WithEvents hook As EventVB.EnumHandler
    4.  
    5. ' Form load
    6. Private Sub Form_Load()
    7.   Set apiLink = New EventVb.ApiFunctions
    8.   Set hook = apiLink.EventHandlerLink
    9.  
    10.   hook.StartHook WH_KEYBOARD_LL,apiLink.AppModuleHandle, 0
    11.  
    12. End Sub
    13.  
    14. ' Form unload
    15. Private Sub Form_Unload(Cancel As Integer)
    16.    hook.StopHook WH_KEYBOARD_LL
    17. End Sub
    18.  
    19. Private Sub hook_HOOKPROCKEYBOARDLL(Action As EventVB.enHookCode, ByVal KeyState As Long, ByVal KeyStrokeInfo As EventVB.ApiKBDLLHOOKSTRUCT, lMsgRet As Long)
    20.  
    21. '\\ Prevent key being passed on....
    22.      lMsgRet = 1
    23.  
    24. End Sub

    HTH,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  16. #16

    Thread Starter
    Member
    Join Date
    Jan 2002
    Posts
    45
    I must be stupid or something.... how do i load the dll into vb?

  17. #17

    Thread Starter
    Member
    Join Date
    Jan 2002
    Posts
    45
    never mind... i got it

  18. #18

    Thread Starter
    Member
    Join Date
    Jan 2002
    Posts
    45
    this is perfect... is there some way in order to use this to input keys as well?? (aka instead of sendkeys)

  19. #19
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    to block keystrokes and mouse movements try this
    VB Code:
    1. Private Declare Function BlockInput Lib "user32" (ByVal fBlock As Long) As Long
    2. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    3. Private Sub Command1_Click()
    4.     DoEvents
    5.     'block the mouse and keyboard input
    6.     BlockInput True
    7.     'wait 10 seconds before unblocking it
    8.     Sleep 10000
    9.     'unblock the mouse and keyboard input
    10.     BlockInput False
    11. End Sub

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

  20. #20

    Thread Starter
    Member
    Join Date
    Jan 2002
    Posts
    45
    Originally posted by MerrionComputin
    In Windows NT/2000/XP you can install a WH_KEYBOARD_LL hook (using the EventVB.dll) thus:

    VB Code:
    1. ' Form declarations
    2. Private WithEvents apiLink As EventVB.ApiFunctions
    3. Private WithEvents hook As EventVB.EnumHandler
    4.  
    5. ' Form load
    6. Private Sub Form_Load()
    7.   Set apiLink = New EventVb.ApiFunctions
    8.   Set hook = apiLink.EventHandlerLink
    9.  
    10.   hook.StartHook WH_KEYBOARD_LL,apiLink.AppModuleHandle, 0
    11.  
    12. End Sub
    13.  
    14. ' Form unload
    15. Private Sub Form_Unload(Cancel As Integer)
    16.    hook.StopHook WH_KEYBOARD_LL
    17. End Sub
    18.  
    19. Private Sub hook_HOOKPROCKEYBOARDLL(Action As EventVB.enHookCode, ByVal KeyState As Long, ByVal KeyStrokeInfo As EventVB.ApiKBDLLHOOKSTRUCT, lMsgRet As Long)
    20.  
    21. '\\ Prevent key being passed on....
    22.      lMsgRet = 1
    23.  
    24. End Sub

    HTH,
    Duncan
    How the heck do i determain the key pressed by the user before i block it??

  21. #21
    Frenzied Member KayJay's Avatar
    Join Date
    Jul 2001
    Location
    Chennai
    Posts
    1,849
    And

    ............................aka instead of sendkeys..........
    Use the SendInput API. Example: -

    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_KEYUP = &H2
    6. Const INPUT_MOUSE = 0
    7. Const INPUT_KEYBOARD = 1
    8. Const INPUT_HARDWARE = 2
    9. Private Type MOUSEINPUT
    10.   dx As Long
    11.   dy As Long
    12.   mouseData As Long
    13.   dwFlags As Long
    14.   time As Long
    15.   dwExtraInfo As Long
    16. End Type
    17. Private Type KEYBDINPUT
    18.   wVk As Integer
    19.   wScan As Integer
    20.   dwFlags As Long
    21.   time As Long
    22.   dwExtraInfo As Long
    23. End Type
    24. Private Type HARDWAREINPUT
    25.   uMsg As Long
    26.   wParamL As Integer
    27.   wParamH As Integer
    28. End Type
    29. Private Type GENERALINPUT
    30.   dwType As Long
    31.   xi(0 To 23) As Byte
    32. End Type
    33. Private Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long, pInputs As GENERALINPUT, ByVal cbSize As Long) As Long
    34. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
    35. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    36. Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    37.  
    38. Private Sub Command1_Click()
    39.     Dim lHandle As Long
    40.     lHandle = FindWindow(vbNullString, "Untitled - Notepad")
    41.     'Set this window to the foreground
    42.     lHandle = SetForegroundWindow(lHandle)
    43.     SendKey VK_H
    44.     SendKey VK_E
    45.     SendKey VK_L
    46.     SendKey VK_L
    47.     SendKey VK_O
    48. End Sub
    49.  
    50. Private Sub SendKey(bKey As Byte)
    51.     Dim GInput(0 To 1) As GENERALINPUT
    52.     Dim KInput As KEYBDINPUT
    53.     KInput.wVk = bKey  'the key we're going to press
    54.     KInput.dwFlags = 0 'press the key
    55.     'copy the structure into the input array's buffer.
    56.     GInput(0).dwType = INPUT_KEYBOARD   ' keyboard input
    57.     CopyMemory GInput(0).xi(0), KInput, Len(KInput)
    58.     'do the same as above, but for releasing the key
    59.     KInput.wVk = bKey  ' the key we're going to realease
    60.     KInput.dwFlags = KEYEVENTF_KEYUP  ' release the key
    61.     GInput(1).dwType = INPUT_KEYBOARD  ' keyboard input
    62.     CopyMemory GInput(1).xi(0), KInput, Len(KInput)
    63.     'send the input now
    64.     Call SendInput(2, GInput(0), Len(GInput(0)))
    65. End Sub

    "Brothers, you asked for it."
    ...Francisco Domingo Carlos Andres Sebastian D'Anconia

  22. #22

    Thread Starter
    Member
    Join Date
    Jan 2002
    Posts
    45
    this is all 1 big loop....

    i want to be able to.. using 1 thing.. not 3 different things... to get any keys beeing pressed... be able to process them.. then block/let them through... AND using the same thing... be able to send keys... because using that method.. it will call the other api and it will go in a big loop back and forth...

    This is very confusing and if you don't understand what i am talking about then i'm sorry for confusing you....

    Right now i need something for me to be able to block SPECIFIC KEYS....

    i've pretty much got the rest of what i need... i just need something that will block specific keys and not the whole keyboard

  23. #23
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    To block a specific key (lets say B) modify the above snippet thus:
    VB Code:
    1. Private Sub hook_HOOKPROCKEYBOARDLL(Action As EventVB.enHookCode, ByVal KeyState As Long, ByVal KeyStrokeInfo As EventVB.ApiKBDLLHOOKSTRUCT, lMsgRet As Long)
    2.  
    3. If KeyStrokeInfo.vkCode = vbKeyB Then
    4. '\\ Prevent key being passed on....
    5.      lMsgRet = 1
    6. End If
    7.  
    8. End Sub

    HTH,
    Duncan

    See rather basic help documentation...

    HTH,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  24. #24

    Thread Starter
    Member
    Join Date
    Jan 2002
    Posts
    45
    i figured it out just before you posted it thx alot anyway... this really helps me alot... not i can do all of the stuff that i stated above !!!

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