|
-
Oct 6th, 2008, 10:34 AM
#1
Thread Starter
Addicted Member
[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!
-
Oct 6th, 2008, 10:40 AM
#2
Re: [2008] System freeze when trying to play a sub using a key (low keyboard hook)
how did you implement they keyboard hook?
-
Oct 6th, 2008, 10:50 AM
#3
Thread Starter
Addicted Member
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/
-
Oct 6th, 2008, 12:16 PM
#4
Addicted Member
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!
-
Oct 6th, 2008, 01:05 PM
#5
Thread Starter
Addicted Member
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?
-
Oct 6th, 2008, 01:31 PM
#6
Addicted Member
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!
-
Oct 6th, 2008, 01:58 PM
#7
Re: [2008] System freeze when trying to play a sub using a key (low keyboard hook)
 Originally Posted by shynet
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
-
Oct 7th, 2008, 11:57 AM
#8
Thread Starter
Addicted Member
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?
-
Oct 7th, 2008, 12:01 PM
#9
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?
-
Oct 7th, 2008, 12:32 PM
#10
Addicted Member
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!
-
Oct 7th, 2008, 05:05 PM
#11
Thread Starter
Addicted Member
Re: [2008] System freeze when trying to play a sub using a key (low keyboard hook)
 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!!
-
Oct 8th, 2008, 08:14 AM
#12
Addicted Member
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!
-
Oct 9th, 2008, 12:08 PM
#13
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|