Roland_Foxx
Dec 9th, 2001, 02:44 PM
A slightly different perspective on this one, tho. Barring the global hooks/memory eat-up/slow OS death spiral that left me quite confused (and Windows quite pissed off at me too, I might add)...I was wondering this.
It keeps being hinted at in the documentation I've been poring over that there's a way to get keystroke information directly from the keyboard's driver, which would seem to bypass the whole mess mentioned above, but I can't seem to find anything else about it. Is this just a pipe dream, or is there some way of doing this through the API...?
MerrionComputin
Dec 10th, 2001, 04:17 AM
I missed the original can of worms...what information do you want to get from the keyboard driver?
If it is just a system wide keyboard hook I have a simple example here (http://www.vbcodelibrary.co.uk/board/viewthread.php?FID=7&TID=322) that may be of interest.
HTH,
Duncan
Hack
Dec 10th, 2001, 08:37 AM
Here is a example that I think might get you going, and its not too messy.Const VK_H = 72
Const VK_E = 69
Const VK_L = 76
Const VK_O = 79
Const KEYEVENTF_EXTENDEDKEY = &H1
Const KEYEVENTF_KEYUP = &H2
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Sub Form_KeyPress(KeyAscii As Integer)
'Print the key on the form
Me.Print Chr$(KeyAscii);
End Sub
Private Sub Form_Paint()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
'Clear the form
Me.Cls
keybd_event VK_H, 0, 0, 0 ' press H
keybd_event VK_H, 0, KEYEVENTF_KEYUP, 0 ' release H
keybd_event VK_E, 0, 0, 0 ' press E
keybd_event VK_E, 0, KEYEVENTF_KEYUP, 0 ' release E
keybd_event VK_L, 0, 0, 0 ' press L
keybd_event VK_L, 0, KEYEVENTF_KEYUP, 0 ' release L
keybd_event VK_L, 0, 0, 0 ' press L
keybd_event VK_L, 0, KEYEVENTF_KEYUP, 0 ' release L
keybd_event VK_O, 0, 0, 0 ' press O
keybd_event VK_O, 0, KEYEVENTF_KEYUP, 0 ' release O
End SubThe keybd_event function synthesizes a keystroke. The system can use such a synthesized keystroke to generate a WM_KEYUP or WM_KEYDOWN message. The keyboard driver’s interrupt handler calls the keybd_event function.
Roland_Foxx
Dec 10th, 2001, 10:18 AM
Well, the original can of worms (which is now buried in the depths of the board) was discussing ways to have VB programs receive keystrokes even when its form didn't have the focus.
One way which was discussed was to create a DLL that held a global hook to capture keystrokes from all processes...but the end result (it seems) was some serious system slowdown, as every process had to load the pointer to the DLL and pass it the information.
On the other hand, it seems that it might be possible to simply (hah!) have VB talk directly to the device driver itself, getting a copy of the keyboard input as they are passed from the driver into Windows, and thus being able to respond without having the focus...which is what I'm trying to figure out.