Results 1 to 5 of 5

Thread: fdsfdsf

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    i live where you don't
    Posts
    76

    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?

  2. #2
    Megatron
    Guest

    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)?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2001
    Location
    i live where you don't
    Posts
    76
    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.

  4. #4
    Megatron
    Guest
    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.

  5. #5
    Megatron
    Guest
    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:
    1. Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
    2. Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
    3. 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
    4. Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
    5. Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
    6. Private Const WH_KEYBOARD = 2
    7. Private hHook As Long
    8. Private hModule As Long
    9.  
    10. Private Sub Form_Load()
    11.        
    12.     Dim lpfn As Long
    13.    
    14.     'Change path to path of the dll.
    15.     hModule = LoadLibrary("KeyboardDll.dll")
    16.     If hModule <> 0 Then
    17.         lpfn = GetProcAddress(hModule, "_KeyboardProc@12")
    18.         If lpfn <> 0 Then hHook = SetWindowsHookEx(WH_KEYBOARD, lpfn, hModule, 0)
    19.     End If
    20.    
    21. End Sub
    22.  
    23. Private Sub Form_Unload(Cancel As Integer)
    24.     If hHook <> 0 Then UnhookWindowsHookEx (hHook)
    25. 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
  •  



Click Here to Expand Forum to Full Width