|
-
May 24th, 2002, 03:22 PM
#1
Thread Starter
Member
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
-
May 24th, 2002, 04:43 PM
#2
Member
Search the net (Or the forum) for 'Keyboard hook'
-
May 24th, 2002, 06:09 PM
#3
Thread Starter
Member
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
-
May 24th, 2002, 06:16 PM
#4
This answers your first issue:
VB Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
MsgBox "User Pressed Enter"
'Code Here
End If
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.
-
May 25th, 2002, 02:57 AM
#5
Member
Apparently, in VB, to do a keyboard hook you need to use a DLL
-
May 25th, 2002, 05:56 AM
#6
Or lockin all keys in the keyboard using code ...(which is damn long)
-
May 25th, 2002, 09:38 AM
#7
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?
-
May 28th, 2002, 10:36 PM
#8
Thread Starter
Member
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??
-
May 28th, 2002, 10:55 PM
#9
The picture isn't missing
the apiguide example
VB Code:
'In a module
Public Const WH_KEYBOARD = 2
Public Const VK_SHIFT = &H10
Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
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
Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public hHook As Long
Public Function KeyboardProc(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'if idHook is less than zero, no further processing is required
If idHook < 0 Then
'call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
Else
'check if SHIFT-S is pressed
If (GetKeyState(VK_SHIFT) And &HF0000000) And wParam = Asc("S") Then
'show the result
Form1.Print "Shift-S pressed ..."
End If
'call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
End If
End Function
'In a form, called Form1
Private Sub Form_Load()
'KPD-Team 2000
'URL: [url]http://www.allapi.net/[/url]
'set a keyboard hook
hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, App.hInstance, App.ThreadID)
End Sub
Private Sub Form_Unload(Cancel As Integer)
'remove the windows-hook
UnhookWindowsHookEx hHook
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  .
-
May 28th, 2002, 11:00 PM
#10
Thread Starter
Member
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??
-
May 28th, 2002, 11:03 PM
#11
The picture isn't missing
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  .
-
May 29th, 2002, 02:15 AM
#12
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)
-
May 29th, 2002, 08:34 AM
#13
Thread Starter
Member
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
-
Jun 1st, 2002, 11:05 AM
#14
Thread Starter
Member
-
Jun 1st, 2002, 01:11 PM
#15
Frenzied Member
In Windows NT/2000/XP you can install a WH_KEYBOARD_LL hook (using the EventVB.dll) thus:
VB Code:
' Form declarations
Private WithEvents apiLink As EventVB.ApiFunctions
Private WithEvents hook As EventVB.EnumHandler
' Form load
Private Sub Form_Load()
Set apiLink = New EventVb.ApiFunctions
Set hook = apiLink.EventHandlerLink
hook.StartHook WH_KEYBOARD_LL,apiLink.AppModuleHandle, 0
End Sub
' Form unload
Private Sub Form_Unload(Cancel As Integer)
hook.StopHook WH_KEYBOARD_LL
End Sub
Private Sub hook_HOOKPROCKEYBOARDLL(Action As EventVB.enHookCode, ByVal KeyState As Long, ByVal KeyStrokeInfo As EventVB.ApiKBDLLHOOKSTRUCT, lMsgRet As Long)
'\\ Prevent key being passed on....
lMsgRet = 1
End Sub
HTH,
Duncan
-
Jun 1st, 2002, 01:18 PM
#16
Thread Starter
Member
I must be stupid or something.... how do i load the dll into vb?
-
Jun 1st, 2002, 01:19 PM
#17
Thread Starter
Member
-
Jun 1st, 2002, 01:22 PM
#18
Thread Starter
Member
this is perfect... is there some way in order to use this to input keys as well?? (aka instead of sendkeys)
-
Jun 1st, 2002, 01:29 PM
#19
Frenzied Member
to block keystrokes and mouse movements try this
VB Code:
Private Declare Function BlockInput Lib "user32" (ByVal fBlock As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
DoEvents
'block the mouse and keyboard input
BlockInput True
'wait 10 seconds before unblocking it
Sleep 10000
'unblock the mouse and keyboard input
BlockInput False
End Sub
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Jun 1st, 2002, 01:31 PM
#20
Thread Starter
Member
Originally posted by MerrionComputin
In Windows NT/2000/XP you can install a WH_KEYBOARD_LL hook (using the EventVB.dll) thus:
VB Code:
' Form declarations
Private WithEvents apiLink As EventVB.ApiFunctions
Private WithEvents hook As EventVB.EnumHandler
' Form load
Private Sub Form_Load()
Set apiLink = New EventVb.ApiFunctions
Set hook = apiLink.EventHandlerLink
hook.StartHook WH_KEYBOARD_LL,apiLink.AppModuleHandle, 0
End Sub
' Form unload
Private Sub Form_Unload(Cancel As Integer)
hook.StopHook WH_KEYBOARD_LL
End Sub
Private Sub hook_HOOKPROCKEYBOARDLL(Action As EventVB.enHookCode, ByVal KeyState As Long, ByVal KeyStrokeInfo As EventVB.ApiKBDLLHOOKSTRUCT, lMsgRet As Long)
'\\ Prevent key being passed on....
lMsgRet = 1
End Sub
HTH,
Duncan
How the heck do i determain the key pressed by the user before i block it??
-
Jun 1st, 2002, 01:44 PM
#21
Frenzied Member
And
............................aka instead of sendkeys..........
Use the SendInput API. Example: -
VB Code:
Const VK_H = 72
Const VK_E = 69
Const VK_L = 76
Const VK_O = 79
Const KEYEVENTF_KEYUP = &H2
Const INPUT_MOUSE = 0
Const INPUT_KEYBOARD = 1
Const INPUT_HARDWARE = 2
Private Type MOUSEINPUT
dx As Long
dy As Long
mouseData As Long
dwFlags As Long
time As Long
dwExtraInfo As Long
End Type
Private Type KEYBDINPUT
wVk As Integer
wScan As Integer
dwFlags As Long
time As Long
dwExtraInfo As Long
End Type
Private Type HARDWAREINPUT
uMsg As Long
wParamL As Integer
wParamH As Integer
End Type
Private Type GENERALINPUT
dwType As Long
xi(0 To 23) As Byte
End Type
Private Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long, pInputs As GENERALINPUT, ByVal cbSize As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Command1_Click()
Dim lHandle As Long
lHandle = FindWindow(vbNullString, "Untitled - Notepad")
'Set this window to the foreground
lHandle = SetForegroundWindow(lHandle)
SendKey VK_H
SendKey VK_E
SendKey VK_L
SendKey VK_L
SendKey VK_O
End Sub
Private Sub SendKey(bKey As Byte)
Dim GInput(0 To 1) As GENERALINPUT
Dim KInput As KEYBDINPUT
KInput.wVk = bKey 'the key we're going to press
KInput.dwFlags = 0 'press the key
'copy the structure into the input array's buffer.
GInput(0).dwType = INPUT_KEYBOARD ' keyboard input
CopyMemory GInput(0).xi(0), KInput, Len(KInput)
'do the same as above, but for releasing the key
KInput.wVk = bKey ' the key we're going to realease
KInput.dwFlags = KEYEVENTF_KEYUP ' release the key
GInput(1).dwType = INPUT_KEYBOARD ' keyboard input
CopyMemory GInput(1).xi(0), KInput, Len(KInput)
'send the input now
Call SendInput(2, GInput(0), Len(GInput(0)))
End Sub
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
-
Jun 1st, 2002, 01:51 PM
#22
Thread Starter
Member
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
-
Jun 1st, 2002, 02:02 PM
#23
Frenzied Member
To block a specific key (lets say B) modify the above snippet thus:
VB Code:
Private Sub hook_HOOKPROCKEYBOARDLL(Action As EventVB.enHookCode, ByVal KeyState As Long, ByVal KeyStrokeInfo As EventVB.ApiKBDLLHOOKSTRUCT, lMsgRet As Long)
If KeyStrokeInfo.vkCode = vbKeyB Then
'\\ Prevent key being passed on....
lMsgRet = 1
End If
End Sub
HTH,
Duncan
See rather basic help documentation...
HTH,
Duncan
-
Jun 1st, 2002, 02:04 PM
#24
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|