|
-
Nov 3rd, 2001, 03:03 PM
#1
Thread Starter
Junior Member
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!
-
Nov 3rd, 2001, 08:09 PM
#2
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?
-
Nov 4th, 2001, 04:03 AM
#3
Hyperactive Member
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.
-
Nov 4th, 2001, 09:21 AM
#4
New Member
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.
-
Nov 5th, 2001, 07:34 AM
#5
Fanatic Member
Crispin
VB6 ENT SP5
VB.NET
W2K ADV SVR SP3
WWW.BLOCKSOFT.CO.UK
[Microsoft Basic: 1976-2001, RIP]
-
Nov 5th, 2001, 08:48 AM
#6
Conquistador
VB Code:
'in form
Private Sub Form_Load()
Hook
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnHook
End Sub
'in module
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
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Const WH_KEYBOARD = 2
Dim lpPrevProc As Long
Sub Hook()
lpPrevProc = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, 0, 0)
End Sub
Sub UnHook()
UnhookWindowsHookEx lpPrevProc
End Sub
Function KeyboardProc(ByVal code As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Debug.Print code & ":" & wParam & ":" & lParam
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|