Results 1 to 10 of 10

Thread: hook

  1. #1

    Thread Starter
    Member frix199's Avatar
    Join Date
    Dec 2005
    Location
    Thessaloniki, Greece iamthebest: True
    Posts
    59

    Exclamation hook

    hello!

    do you know any good keyboard hook and how can i make it work?

    i was stuck in one, so any suggestions would b appreciated...

    tnx!!!

    ...and a happy new year...
    Last edited by frix199; Jan 3rd, 2006 at 07:23 PM. Reason: forgot e-mail notification...


    Human beings are a disease, a cancer of this planet, you are a plague, and we are the cure.

  2. #2
    Fanatic Member
    Join Date
    May 2005
    Posts
    898

    Re: hook

    Can you be more specific?

    ALT!!
    "so just keep in mind that fantasy is not the same as realtiy and make sure u remember that wii sports may be fun but u cant count on it as exercise ok cool bye" - HungarianHuman

  3. #3

    Thread Starter
    Member frix199's Avatar
    Join Date
    Dec 2005
    Location
    Thessaloniki, Greece iamthebest: True
    Posts
    59

    Re: hook

    mmm...yea...

    i need a keyboard hook... you know, catching and sending keystrokes with another window active...

    BUT, i cant make it work

    so plz help

    bibii


    Human beings are a disease, a cancer of this planet, you are a plague, and we are the cure.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: hook

    Found this using Google. That article explains how to implement a keyboard hook. For more specific information, perhaps you should tell us what you've done so far and what issues you are having.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member frix199's Avatar
    Join Date
    Dec 2005
    Location
    Thessaloniki, Greece iamthebest: True
    Posts
    59

    Re: hook

    i've seen that myself ...

    BUT, i cant make it work!!!

    1.i make the module
    2.how i hook it?




    tnxxx


    Human beings are a disease, a cancer of this planet, you are a plague, and we are the cure.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: hook

    That site has full source code. What more can we tell you? You've already been prompted twice for more information.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Member frix199's Avatar
    Join Date
    Dec 2005
    Location
    Thessaloniki, Greece iamthebest: True
    Posts
    59

    Re: hook

    ok, ok

    VB Code:
    1. <MarshalAs(UnmanagedType.FunctionPtr)> _
    2. Private callback As KeyboardHookDelegate
    3.  
    4. Public Sub HookKeyboard()
    5.   callback = New KeyboardHookDelegate(AddressOf KeyboardCallback)
    6.  
    7.   KeyboardHandle = SetWindowsHookEx( _
    8.     WH_KEYBOARD_LL, callback, _
    9.     Marshal.GetHINSTANCE( _
    10.     [Assembly].GetExecutingAssembly.GetModules()(0)).ToInt32, 0)
    11.  
    12.    Call CheckHooked()
    13.   End Sub

    i add the module, i use the fucntions to hook it as shown [url="http://www.developer.com/net/vb/article.php/10926_2193301_2"]here[/html], but i got this :

    type 'marshalas' is not declared
    type 'keyboardhookdelegate' is not declared
    type 'keyboardhandle' is not declared

    and for all the code...
    its just like the module dissapeared...


    Human beings are a disease, a cancer of this planet, you are a plague, and we are the cure.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: hook

    Now we're getting somewhere. It's much easier to advise when the facts are known.

    I pasted the code from that page into a code file and I got no such errors. The only errors I got were related to Option Strict and missing As clauses, which are easily fixed. It sounds to me like you've omitted sections of that code that are required. Here is the code from that page with several annotations relating to the issues you've mentioned.
    VB Code:
    1. Imports System.Runtime.InteropServices [COLOR=Red]<--- Required to use the MarshalAsAttribute class[/COLOR]
    2. Imports System.Reflection
    3. Imports System.Drawing
    4. Imports System.Threading
    5.  
    6. Module Keyboard
    7.     Public Declare Function UnhookWindowsHookEx Lib "user32" _
    8.       (ByVal hHook As Integer) As Integer
    9.  
    10.     Public Declare Function SetWindowsHookEx Lib "user32" _
    11.       Alias "SetWindowsHookExA" (ByVal idHook As Integer, _
    12.       ByVal lpfn As KeyboardHookDelegate, ByVal hmod As Integer, _
    13.       ByVal dwThreadId As Integer) As Integer
    14.  
    15.     Private Declare Function GetAsyncKeyState Lib "user32" _
    16.       (ByVal vKey As Integer) As Integer
    17.  
    18.     Private Declare Function CallNextHookEx Lib "user32" _
    19.       (ByVal hHook As Integer, _
    20.       ByVal nCode As Integer, _
    21.       ByVal wParam As Integer, _
    22.       ByVal lParam As KBDLLHOOKSTRUCT) As Integer
    23.  
    24.     Public Structure KBDLLHOOKSTRUCT
    25.         Public vkCode As Integer
    26.         Public scanCode As Integer
    27.         Public flags As Integer
    28.         Public time As Integer
    29.         Public dwExtraInfo As Integer
    30.     End Structure
    31.  
    32.     ' Low-Level Keyboard Constants
    33.     Private Const HC_ACTION As Integer = 0
    34.     Private Const LLKHF_EXTENDED As Integer = &H1
    35.     Private Const LLKHF_INJECTED As Integer = &H10
    36.     Private Const LLKHF_ALTDOWN As Integer = &H20
    37.     Private Const LLKHF_UP As Integer = &H80
    38.  
    39.     ' Virtual Keys
    40.     Public Const VK_TAB = &H9
    41.     Public Const VK_CONTROL = &H11
    42.     Public Const VK_ESCAPE = &H1B
    43.     Public Const VK_DELETE = &H2E
    44.  
    45.     Private Const WH_KEYBOARD_LL As Integer = 13&
    46.     Public KeyboardHandle As Integer [COLOR=Red]<--- KeyboardHandle declared here.[/COLOR]
    47.  
    48.  
    49.     ' Implement this function to block as many
    50.     ' key combinations as you'd like
    51.     Public Function IsHooked( _
    52.       ByRef Hookstruct As KBDLLHOOKSTRUCT) As Boolean
    53.  
    54.         Debug.WriteLine("Hookstruct.vkCode: " & Hookstruct.vkCode)
    55.         Debug.WriteLine(Hookstruct.vkCode = VK_ESCAPE)
    56.         Debug.WriteLine(Hookstruct.vkCode = VK_TAB)
    57.  
    58.         If (Hookstruct.vkCode = VK_ESCAPE) And _
    59.           CBool(GetAsyncKeyState(VK_CONTROL) _
    60.           And &H8000) Then
    61.  
    62.             Call HookedState("Ctrl + Esc blocked")
    63.             Return True
    64.         End If
    65.  
    66.         If (Hookstruct.vkCode = VK_TAB) And _
    67.           CBool(Hookstruct.flags And _
    68.           LLKHF_ALTDOWN) Then
    69.  
    70.             Call HookedState("Alt + Tab blockd")
    71.             Return True
    72.         End If
    73.  
    74.         If (Hookstruct.vkCode = VK_ESCAPE) And _
    75.           CBool(Hookstruct.flags And _
    76.             LLKHF_ALTDOWN) Then
    77.  
    78.             Call HookedState("Alt + Escape blocked")
    79.             Return True
    80.         End If
    81.  
    82.         Return False
    83.     End Function
    84.  
    85.     Private Sub HookedState(ByVal Text As String)
    86.         Debug.WriteLine(Text)
    87.     End Sub
    88.  
    89.     Public Function KeyboardCallback(ByVal Code As Integer, _
    90.       ByVal wParam As Integer, _
    91.       ByRef lParam As KBDLLHOOKSTRUCT) As Integer
    92.  
    93.         If (Code = HC_ACTION) Then
    94.             Debug.WriteLine("Calling IsHooked")
    95.  
    96.             If (IsHooked(lParam)) Then
    97.                 Return 1
    98.             End If
    99.  
    100.         End If
    101.  
    102.         Return CallNextHookEx(KeyboardHandle, _
    103.           Code, wParam, lParam)
    104.  
    105.     End Function
    106.  
    107.  
    108.     Public Delegate Function KeyboardHookDelegate( _
    109.       ByVal Code As Integer, _
    110.       ByVal wParam As Integer, ByRef lParam As KBDLLHOOKSTRUCT) _
    111.                    As Integer [COLOR=Red]<--- KeyboardHookDelegate declared here.[/COLOR]
    112.  
    113.     <MarshalAs(UnmanagedType.FunctionPtr)> _
    114.     Private callback As KeyboardHookDelegate
    115.  
    116.     Public Sub HookKeyboard()
    117.         callback = New KeyboardHookDelegate(AddressOf KeyboardCallback)
    118.  
    119.         KeyboardHandle = SetWindowsHookEx( _
    120.           WH_KEYBOARD_LL, callback, _
    121.           Marshal.GetHINSTANCE( _
    122.           [Assembly].GetExecutingAssembly.GetModules()(0)).ToInt32, 0)
    123.  
    124.         Call CheckHooked()
    125.     End Sub
    126.  
    127.     Public Sub CheckHooked()
    128.         If (Hooked()) Then
    129.             Debug.WriteLine("Keyboard hooked")
    130.         Else
    131.             Debug.WriteLine("Keyboard hook failed: " & Err.LastDllError)
    132.         End If
    133.     End Sub
    134.  
    135.     Private Function Hooked()
    136.         Hooked = KeyboardHandle <> 0
    137.     End Function
    138.  
    139.     Public Sub UnhookKeyboard()
    140.         If (Hooked()) Then
    141.             Call UnhookWindowsHookEx(KeyboardHandle)
    142.         End If
    143.     End Sub
    144.  
    145. End Module
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Member frix199's Avatar
    Join Date
    Dec 2005
    Location
    Thessaloniki, Greece iamthebest: True
    Posts
    59

    Re: hook

    ok tnx but now everythings right exept "WH_KEYBOARD_LL" wich is not declared


    Human beings are a disease, a cancer of this planet, you are a plague, and we are the cure.

  10. #10

    Thread Starter
    Member frix199's Avatar
    Join Date
    Dec 2005
    Location
    Thessaloniki, Greece iamthebest: True
    Posts
    59

    Re: hook

    o sh*t... im THAT stupid )

    btw what do i enter instead this(all this cllbacks and things
    ):

    SetWindowsHookEx( _
    WH_KEYBOARD_LL, callback, _
    Marshal.GetHINSTANCE( _
    [Assembly].GetExecutingAssembly.GetModules()(0)).ToInt32, 0)


    Human beings are a disease, a cancer of this planet, you are a plague, and we are the cure.

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