Click to See Complete Forum and Search --> : Keyboard recording?
madddog
Jan 9th, 2000, 10:12 AM
Evening All,
I use a lot of my programs in Autocad(R14), and the API (in my opinion) is still lacking
a lot of functionallity. My question is, is there a way to get VB to record the
keystrokes that I input, then send them to a text box in my program.
Hmmmmmmmm........
Thanks in advance,
Mike
Bob Baddeley
Jan 9th, 2000, 11:52 AM
All I know is that there is something called a hook, and that's what you want. I found one from microsoft called Hooks32, but it's really simple and kind of stupid. I don't know any more, so this is probably a waste of your time. Sigh. Look for hooks though.
Tonio169
Jan 9th, 2000, 04:51 PM
yes, you can do it in vb with API's but i don't know how. i tried researching all about this before but i got bored. i suggest you study about window messages.
onerrorgoto
Jan 9th, 2000, 06:13 PM
You can use hooks to trap events from the keyboard mous etc.
Here is a topic with some code from MSDN.
http://msdn.microsoft.com/library/techart/msdn_hooks32.htm
I also know that I found a program that you could use to record the key board, I think it was on the MSDN site but now I cant' find it. Maybe it was somewhere else :(
I hope this article will help you ab bit on the way.
I will get back if I remember where I found the that program.
------------------
On Error Goto Bed :0)
anders@zsystemdesign.se
Aaron Young
Jan 9th, 2000, 10:07 PM
You can use MessageHooks but this will only work for Activity within your Application unless you link it via a DLL, here's a method I came up with which doesn't use Hooks:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long
Private Declare Function ToAscii Lib "user32" (ByVal uVirtKey As Long, ByVal uScanCode As Long, lpbKeyState As Byte, lpwTransKey As Long, ByVal fuState As Long) As Long
Private Const VK_SHIFT = &H10 'Used by Win9x
Private Const VK_LSHIFT = &HA0 'Used by NT
Private Const VK_RSHIFT = &HA1 'Used by NT
Private Sub Form_Load()
'Need a Very Low Interval to Ensure the Keys are Captured in the Correct Order
Timer1.Interval = 10
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Dim iKey As Integer
Dim iAsc As Long
Dim bKeys(255) As Byte
For iKey = 1 To 255
'Use GetAsyncKeyState to Monitor Keypress From Anywhere in the O/S.
If GetAsyncKeyState(iKey) And iKey <> VK_LSHIFT And iKey <> VK_RSHIFT And iKey <> VK_SHIFT Then Exit For
Next
If iKey < 256 Then
'Get the Current Keyboard State For the Shift Keys Etc..
Call GetKeyboardState(bKeys(0))
While GetAsyncKeyState(iKey)
'Wait for Key to be Released
Wend
'Conver the Key to it's ASCII Equivilant
Call ToAscii(iKey, 0&, bKeys(0), iAsc, 0&)
If iAsc Then
'Store Keypress to Log Here
Debug.Print Chr(iAsc);
End If
End If
End Sub
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.