Results 1 to 13 of 13

Thread: [RESOLVED] [2008] System freeze when trying to play a sub using a key (low keyboard hook)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    155

    Resolved [RESOLVED] [2008] System freeze when trying to play a sub using a key (low keyboard hook)

    Hi guys,
    I have got a problem when trying to play a sub using a shortcut
    key in a low keyboard hook...
    Code:
        Private Shadows Sub KeyDown(ByVal KeyCode As Integer) Handles KeyHook.KeyDown
    If KeyCode=keys.f12 then
    Call MySub
            End If
    when trying to play any of these subs by the key f12 the system freeze for a couple of seconds and the goes back to normal...
    when clicking on a button that Calls the same Sub the system doesn't freeze...
    The sub it calls is a loop with delay (system.threading.thread.sleep(10) )
    and the Application.doevents command.

    How can I fix the problem, so when I press the F12 key my system wont freeze (it doesn't happen to me when trying to call the same sub using a button)...?

    Thank you!

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2008] System freeze when trying to play a sub using a key (low keyboard hook)

    how did you implement they keyboard hook?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    155

    Re: [2008] System freeze when trying to play a sub using a key (low keyboard hook)

    here is the guide (someone that really really helped me from this forum, I'm really sorry for not remembering his name!) gave me this guide:
    http://ih4x.wordpress.com/2008/05/05...d-hook-global/

  4. #4
    Addicted Member
    Join Date
    Mar 2008
    Posts
    143

    Re: [2008] System freeze when trying to play a sub using a key (low keyboard hook)

    The F12 key is reserved for use by the debugger at all times. Check out this link.
    Shut up and eat your banana!

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    155

    Re: [2008] System freeze when trying to play a sub using a key (low keyboard hook)

    I have changed the key (for example to 1 (number key) ) and it still doesn't work...
    any ideas?

  6. #6
    Addicted Member
    Join Date
    Mar 2008
    Posts
    143

    Re: [2008] System freeze when trying to play a sub using a key (low keyboard hook)

    What happens when you do..

    Code:
    Private Shadows Sub KeyDown(ByVal KeyCode As Integer) Handles KeyHook.KeyDown
        If KeyCode=keys.D1 then
            MyButton.PerformClick
        End If
    ??

    (substitute button name for 'MyButton', of course )
    Shut up and eat your banana!

  7. #7
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: [2008] System freeze when trying to play a sub using a key (low keyboard hook)

    Quote Originally Posted by shynet
    here is the guide (someone that really really helped me from this forum, I'm really sorry for not remembering his name!) gave me this guide:
    http://ih4x.wordpress.com/2008/05/05...d-hook-global/
    Hi,

    I've readed the link and found this:

    This will basically convert the key that was pressed to its char equivalent, and then save it to a log file, however this isn’t suitable for all the keys (E.g. space, ctrl, alt, shift, etc) as they do not have char characters.


    That could mean that the key your trying isn't suitable.
    You can test it to try the key in the example.

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    155

    Re: [2008] System freeze when trying to play a sub using a key (low keyboard hook)

    Sorry for the late respond,
    I have tried the Keys Space, Delete, or just P key to check everything and the system still kind of stucks when pressing it (Mouse can be moved but I can't do anything except moving it)
    and I have tried what michaelerice said but it still doesn't work...
    any more ideas?

  9. #9
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2008] System freeze when trying to play a sub using a key (low keyboard hook)

    did you try changing the routine that actually gets calls to not do any thread sleeping, and see if there is any different result?

  10. #10
    Addicted Member
    Join Date
    Mar 2008
    Posts
    143

    Re: [2008] System freeze when trying to play a sub using a key (low keyboard hook)

    Since clicking the button doesn't cause you grief, but PerformClick() on the same button does, you may be having a cross-threading issue that isn't apparent. Try this...

    Code:
    Delegate Sub InvokeDelegate()
    ...
    
    Private Shadows Sub KeyDown(ByVal KeyCode As Integer) Handles KeyHook.KeyDown
        If KeyCode=keys.D1 then
            Me.BeginInvoke(New InvokeDelegate(AddressOf MyButton.PerformClick))
        End If
    Shut up and eat your banana!

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    155

    Re: [2008] System freeze when trying to play a sub using a key (low keyboard hook)

    Quote Originally Posted by michaelerice
    Since clicking the button doesn't cause you grief, but PerformClick() on the same button does, you may be having a cross-threading issue that isn't apparent. Try this...

    Code:
    Delegate Sub InvokeDelegate()
    ...
    
    Private Shadows Sub KeyDown(ByVal KeyCode As Integer) Handles KeyHook.KeyDown
        If KeyCode=keys.D1 then
            Me.BeginInvoke(New InvokeDelegate(AddressOf MyButton.PerformClick))
        End If
    Thanks!!! that really worked!

    I read some info about the Delegate in vb .net , and I want to understand why this happend and what cross threading issue means?
    I will read more about the delegate, but what the cross threading issue means?

    Thanks!!

  12. #12
    Addicted Member
    Join Date
    Mar 2008
    Posts
    143

    Re: [2008] System freeze when trying to play a sub using a key (low keyboard hook)

    Here is a link that can probably explain it better than I:

    http://msdn.microsoft.com/en-us/library/ms171728.aspx
    Shut up and eat your banana!

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    May 2008
    Posts
    155

    Re: [2008] System freeze when trying to play a sub using a key (low keyboard hook)

    Thanks again, but now I noticed that other keys I press doesn't log anymore
    after pressing the key I assigned to the delegate. how can I make the keys log again after the key I assigned was pressed?

    EDIT:
    Just moved the code to the bottom of the sub so it won't "smash" other commands after it,
    thank you very much!
    Last edited by shynet; Oct 9th, 2008 at 04:54 PM.

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