|
-
Jan 11th, 2002, 03:38 PM
#1
Thread Starter
Lively Member
fdsfdsf
i have two questions:
1) is it possible to check to see if a key's been pressed without having to check each and every one in a loop? i'm looking for something like Form_KeyDown, but that captures all keystrokes.
2) i know how to retrieve text from a text box using api given its handle, but how can i get text from inside a webpage?
-
Jan 11th, 2002, 04:13 PM
#2
Re: fdsfdsf
Originally posted by KrazyGamer
is it possible to check to see if a key's been pressed without having to check each and every one in a loop? i'm looking for something like Form_KeyDown, but that captures all keystrokes.
You mean globally (system-wide)? Or locally (just within your app)?
-
Jan 11th, 2002, 07:13 PM
#3
Thread Starter
Lively Member
globally. i've already made an app to capture the keys using getkeyasynch, but i want to make it so it only captures when anything on the keyboard's pressed. in other words, i don't want it to lop around unless something's actually been pressed.
-
Jan 12th, 2002, 12:53 PM
#4
The only method I can think of is installing a global WH_KEYBOARD hook. To do this, you need to create create the procedure in a C++ DLL.
For example.
Code:
#include <windows.h>
#include <iostream>
using namespace std;
LRESULT CALLBACK KeyboardProc(int,WPARAM,LPARAM);
HHOOK hHook;
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if( wParam == B )
{
ofstream file("MyLog.txt");
file << "B was pressed";
file.close();
}
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
Compile that, and install a hook like you normally would. Instead of specifying a local procedure though, you need to specify the procedure in the DLL. You can do this by calling the LoadLibrary function to load the DLL, and GetProcAddress to get the address of the function.
-
Jan 12th, 2002, 12:56 PM
#5
Here's an example of loading the DLL. Just change the name of the file and function to corrospond with the name you used.
VB Code:
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private 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
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Const WH_KEYBOARD = 2
Private hHook As Long
Private hModule As Long
Private Sub Form_Load()
Dim lpfn As Long
'Change path to path of the dll.
hModule = LoadLibrary("KeyboardDll.dll")
If hModule <> 0 Then
lpfn = GetProcAddress(hModule, "_KeyboardProc@12")
If lpfn <> 0 Then hHook = SetWindowsHookEx(WH_KEYBOARD, lpfn, hModule, 0)
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
If hHook <> 0 Then UnhookWindowsHookEx (hHook)
End Sub
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
|