| | | Forum God
       
Group: Forum Members Last Login: 7/15/2011 3:57:36 PM Posts: 371, Visits: 208 |
| Hi Everybody, I was reading an earlier thread about the start button being disabled. That sparked my interest, 'cause as a programmer I sure would like to be able to control the keyboard at any point in my application. The solution lead to an API(which from lack of knowledge makes me ill:sick So I go on my search to learn more about API and to create some reusable code to do the job. I found an article describing such code. But it doesn't seem to be working for me. I'm sure the problem rests between the keyboard and the back of my chair! If someone has the time would you go to this site and see if you can get this to work? Here's the site: http://www.codeguru.com/vb/gen/vb_system/keyboard/article.php/c4829 It seems that SetWindowsHookEx in the following sub returns 0 for me every time Public Sub HookKeyboard() KeyboardHandle = SetWindowsHookEx( _ WH_KEYBOARD_LL, AddressOf KeyboardCallback, _ App.hInstance, 0&
Thus the following code is executed. Debug.Print "Keyboard hook failed: " & Err.LastDllError Also, as I'm a noobe in this area: Can I Debug and StepInto such code? In code listing at the end of the article, is ControlEscape the only key combination being blocked? Is ControlEscape the same as the Windows Key(ya know the one between Ctrl and Alt)? If someone's got the time I would be estatic! TIA
|
| | | | 
Forum God
       
Group: Forum Members Last Login: 6/24/2009 3:34:33 AM Posts: 511, Visits: 265 |
| Public Sub HookKeyboard() KeyboardHandle = SetWindowsHookEx( _ WH_KEYBOARD_LL, AddressOf KeyboardCallback, _ App.hInstance, 0& Try adding a "ByVal" before that "0&". |
| | | | Forum God
       
Group: Forum Members Last Login: 7/15/2011 3:57:36 PM Posts: 371, Visits: 208 |
| Hey DigiRev, Thanks for replying! This has been racking my brain for two days now! I shouldn't spend so much time on it, but if I could get this working I believe I could trap about any type of message. This code just happens to test for keyboard message If (Code = HC_ACTION) Then 'Its a keyboard message After it's trapped it's then passed on to windows or the next hook that's doing the same thing. Seems like a powerful technique to know! All parameters in the function SetWindowsHookEx IS declared ByVal so I was doubtful. Public 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 But I tried it anyways like so.. Public Sub HookKeyboard() KeyboardHandle = SetWindowsHookEx( _ WH_KEYBOARD_LL, AddressOf KeyboardCallback, _ App.hInstance, ByVal 0& ...... And still NoGo! But thanks for trying. 
|
| | | | 
Forum God
       
Group: Forum Members Last Login: 6/24/2009 3:34:33 AM Posts: 511, Visits: 265 |
| I think I know the problem.  You're not passing the ThreadID...like this: Public Sub HookKeyboard() KeyboardHandle = SetWindowsHookEx( _ WH_KEYBOARD_LL, AddressOf KeyboardCallback, _ App.hInstance, App.ThreadID |
| | | | Forum God
       
Group: Forum Members Last Login: 7/15/2011 3:57:36 PM Posts: 371, Visits: 208 |
| Hi Thanks but that didn't work either. It did get me a little excited for a couple of minutes though! 
|
| | | | Forum God
       
Group: Forum Members Last Login: 3/13/2006 2:34:13 AM Posts: 794, Visits: 338 |
| From that link you gave at start thread... "If the Code is 0 then we want to convert the lParam to the type we know it is, a KBDLLHOOKSTRUCT, handle the keyboard input, and return 1 to indicate that the input was handled." try looking in that area.
Returning zero is 'good' using his special wrapper, but I think the problem is coming into how it is handled. I'll check back here later.
Post back with resolve if/when it comes please. I think you can get! Yes I do!
|
| | | | 
Forum God
       
Group: Forum Members Last Login: 6/24/2009 3:34:33 AM Posts: 511, Visits: 265 |
| | | | | Forum God
       
Group: Forum Members Last Login: 3/13/2006 2:34:13 AM Posts: 794, Visits: 338 |
| I've tried to Impliment the Keyboard hook (class, form, module - oh my), into my own project, but get same results. I wonder if that Kimmel guy just gave enough info for an empty wrapper....
Here is the next best example I found on net:
+ = Keyboard Hook example that works.
|
| | | | 
Forum God
       
Group: Forum Members Last Login: 6/24/2009 3:34:33 AM Posts: 511, Visits: 265 |
| | |
|
|