﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>A1VBCode Forums / Classic Visual Basic (VB 6 or earlier) / General Visual Basic  / Keyboard Hook / Latest Posts</title><generator>InstantForum.NET v4.1.1</generator><description>A1VBCode Forums</description><link>http://www.a1vbcode.com/vbforums/</link><webMaster>forums@a1vbcode.com</webMaster><lastBuildDate>Thu, 17 May 2012 02:07:27 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Keyboard Hook</title><link>http://www.a1vbcode.com/vbforums/Topic2768-3-1.aspx</link><description>&lt;P&gt;&lt;FONT face=Tahoma&gt;I've never tried to hook the keyboard, I just used the GetAsyncKeyState() API function:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#3333dd&gt;Public Declare Function&lt;/FONT&gt; GetAsyncKeyState &lt;FONT color=#3333dd&gt;Lib&lt;/FONT&gt; "user32" &lt;FONT color=#3333dd&gt;Alias&lt;/FONT&gt; "GetAsyncKeyState" (&lt;FONT color=#3333dd&gt;ByVal&lt;/FONT&gt; vKey &lt;FONT color=#3333dd&gt;As Long&lt;/FONT&gt;) &lt;FONT color=#3333dd&gt;As Integer&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;a target=_blank href="http://www.mentalis.org/apilist/GetAsyncKeyState.shtml"&gt;&lt;FONT face=Tahoma&gt;http://www.mentalis.org/apilist/GetAsyncKeyState.shtml&lt;/FONT&gt;&lt;/A&gt;&lt;FONT face=Tahoma&gt; for more info. &lt;img src='images/emotions/smile.gif' height='20' width='20' border='0' title='Smile' align='absmiddle'&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;</description><pubDate>Mon, 23 Aug 2004 20:35:18 GMT</pubDate><dc:creator>DigiRev</dc:creator></item><item><title>RE: Keyboard Hook</title><link>http://www.a1vbcode.com/vbforums/Topic2768-3-1.aspx</link><description>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....&lt;br&gt;&lt;br&gt;Here is the next best example I found on net:&lt;br&gt;&lt;img src="http://images.google.com/images?q=tbn:Hqsk4yPyCJMJ:members.iinet.net.au/~daveb/keyboard.jpg"&gt; + &lt;img src="http://images.google.com/images?q=tbn:GzuxjpcOx24J:www.tolsonmessenger.co.uk/images/hook.gif"&gt; = Keyboard Hook example that works.&lt;br&gt;&lt;br&gt;</description><pubDate>Mon, 23 Aug 2004 17:21:47 GMT</pubDate><dc:creator>pso</dc:creator></item><item><title>RE: Keyboard Hook</title><link>http://www.a1vbcode.com/vbforums/Topic2768-3-1.aspx</link><description>&lt;P&gt;This might be able to help you out a little.&lt;/P&gt;&lt;P&gt;&lt;a target=_blank href="http://www.mentalis.org/apilist/SetWindowsHookEx.shtml"&gt;http://www.mentalis.org/apilist/SetWindowsHookEx.shtml&lt;/A&gt;#&lt;/P&gt;</description><pubDate>Mon, 23 Aug 2004 05:48:34 GMT</pubDate><dc:creator>DigiRev</dc:creator></item><item><title>RE: Keyboard Hook</title><link>http://www.a1vbcode.com/vbforums/Topic2768-3-1.aspx</link><description>From that link you gave at start thread...&lt;br&gt;"If the Code is 0 then we want to &lt;b&gt;convert the lParam to the type we know it is, a &lt;font color="#FF0000"&gt;KBDLLHOOKSTRUCT&lt;/b&gt;&lt;/font&gt;, handle the keyboard input, and return 1 to indicate that the input was handled."&lt;br&gt; try looking in that area.&lt;br&gt;&lt;br&gt;Returning zero is 'good' using his special wrapper, but I think the problem is coming into how it is handled.&lt;br&gt;I'll check back here later.&lt;br&gt;&lt;br&gt;Post back with resolve if/when it comes please.&lt;br&gt;I think you can get! Yes I do!&lt;br&gt;</description><pubDate>Sun, 22 Aug 2004 23:54:56 GMT</pubDate><dc:creator>pso</dc:creator></item><item><title>RE: Keyboard Hook</title><link>http://www.a1vbcode.com/vbforums/Topic2768-3-1.aspx</link><description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;Thanks but that didn't work either.  It did get me a little excited for a couple of minutes though! &lt;img src='images/emotions/laugh.gif' height='20' width='20' border='0' title='Laugh' align='absmiddle'&gt;&lt;/P&gt;</description><pubDate>Fri, 20 Aug 2004 21:02:36 GMT</pubDate><dc:creator>TallOne</dc:creator></item><item><title>RE: Keyboard Hook</title><link>http://www.a1vbcode.com/vbforums/Topic2768-3-1.aspx</link><description>&lt;P&gt;I think I know the problem. &lt;img src='images/emotions/smile.gif' height='20' width='20' border='0' title='Smile' align='absmiddle'&gt;&lt;/P&gt;&lt;P&gt;You're not passing the ThreadID...like this:&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT color=#3333dd&gt;Public Sub&lt;/FONT&gt; HookKeyboard()&lt;BR&gt;  KeyboardHandle = SetWindowsHookEx( _&lt;BR&gt;    WH_KEYBOARD_LL, &lt;FONT color=#3333dd&gt;AddressOf&lt;/FONT&gt; KeyboardCallback, _&lt;BR&gt;    App.hInstance, &lt;STRONG&gt;&lt;U&gt;&lt;FONT color=#ff1111&gt;App.ThreadID&lt;/FONT&gt;&lt;/U&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;</description><pubDate>Fri, 20 Aug 2004 17:10:37 GMT</pubDate><dc:creator>DigiRev</dc:creator></item><item><title>RE: Keyboard Hook</title><link>http://www.a1vbcode.com/vbforums/Topic2768-3-1.aspx</link><description>&lt;P&gt;Hey DigiRev,&lt;/P&gt;&lt;P&gt;Thanks for replying!  This has been racking my brain for two days now!  &lt;img src='images/emotions/angry.gif' height='20' width='20' border='0' title='Angry' align='absmiddle'&gt;  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&lt;/P&gt;&lt;P&gt;&lt;SPAN class=codeKeyword&gt;If&lt;/SPAN&gt; (Code = HC_ACTION) &lt;SPAN class=codeKeyword&gt;Then 'Its a keyboard message&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=codeKeyword&gt;&lt;/SPAN&gt;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!&lt;/P&gt;&lt;P&gt;All parameters in the function SetWindowsHookEx IS declared ByVal so I was doubtful.&lt;/P&gt;&lt;P&gt;Public Declare Function SetWindowsHookEx Lib "user32" _&lt;BR&gt;  Alias "SetWindowsHookExA" (ByVal idHook As Long, _&lt;BR&gt;                             ByVal lpfn As Long, _&lt;BR&gt;                             ByVal hmod As Long, _&lt;BR&gt;                             ByVal dwThreadId As Long) As Long&lt;/P&gt;&lt;P&gt;But I tried it anyways like so..&lt;/P&gt;&lt;P&gt;Public Sub HookKeyboard()&lt;BR&gt;  KeyboardHandle = SetWindowsHookEx( _&lt;BR&gt;    WH_KEYBOARD_LL, AddressOf KeyboardCallback, _&lt;BR&gt;    App.hInstance, ByVal 0&amp;amp&lt;img src='images/emotions/wink.gif' height='20' width='20' border='0' title='Wink' align='absmiddle'&gt;......&lt;/P&gt;&lt;P&gt;And still NoGo!  But thanks for trying. &lt;img src='images/emotions/smile.gif' height='20' width='20' border='0' title='Smile' align='absmiddle'&gt;&lt;/P&gt;</description><pubDate>Fri, 20 Aug 2004 14:56:12 GMT</pubDate><dc:creator>TallOne</dc:creator></item><item><title>RE: Keyboard Hook</title><link>http://www.a1vbcode.com/vbforums/Topic2768-3-1.aspx</link><description>&lt;P&gt;&lt;SPAN class=codeKeyword&gt;Public&lt;/SPAN&gt; &lt;SPAN class=codeKeyword&gt;Sub&lt;/SPAN&gt; HookKeyboard()&lt;BR&gt;  KeyboardHandle = SetWindowsHookEx( _&lt;BR&gt;    WH_KEYBOARD_LL, &lt;SPAN class=codeKeyword&gt;AddressOf&lt;/SPAN&gt; KeyboardCallback, _&lt;BR&gt;    App.hInstance, 0&amp;amp;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Try adding a "ByVal" before that "0&amp;amp;".&lt;/P&gt;</description><pubDate>Fri, 20 Aug 2004 03:16:14 GMT</pubDate><dc:creator>DigiRev</dc:creator></item><item><title>Keyboard Hook</title><link>http://www.a1vbcode.com/vbforums/Topic2768-3-1.aspx</link><description>&lt;P&gt;Hi Everybody,&lt;/P&gt;&lt;P&gt;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&lt;img src='images/emotions/smile.gif' height='20' width='20' border='0' title='Smile' align='absmiddle'&gt;  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.&lt;img src='images/emotions/mad.gif' height='20' width='20' border='0' title='Mad' align='absmiddle'&gt;  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:&lt;/P&gt;&lt;P&gt;&lt;a target=_blank href="http://www.codeguru.com/vb/gen/vb_system/keyboard/article.php/c4829"&gt;http://www.codeguru.com/vb/gen/vb_system/keyboard/article.php/c4829&lt;/A&gt;&lt;/P&gt;&lt;P&gt;It seems that SetWindowsHookEx in the following sub returns 0 for me every time&lt;/P&gt;&lt;P&gt;&lt;SPAN class=codeKeyword&gt;Public&lt;/SPAN&gt; &lt;SPAN class=codeKeyword&gt;Sub&lt;/SPAN&gt; HookKeyboard()&lt;BR&gt;  KeyboardHandle = SetWindowsHookEx( _&lt;BR&gt;    WH_KEYBOARD_LL, &lt;SPAN class=codeKeyword&gt;AddressOf&lt;/SPAN&gt; KeyboardCallback, _&lt;BR&gt;    App.hInstance, 0&amp;amp&lt;img src='images/emotions/wink.gif' height='20' width='20' border='0' title='Wink' align='absmiddle'&gt;&lt;BR&gt;&lt;/P&gt;&lt;P&gt;Thus the following code is executed.&lt;/P&gt;&lt;P&gt;Debug.&lt;SPAN class=codeKeyword&gt;Print&lt;/SPAN&gt; "Keyboard hook failed: " &amp;amp; &lt;SPAN class=codeKeyword&gt;Err&lt;/SPAN&gt;.LastDllError&lt;/P&gt;&lt;P&gt;Also, as I'm a noobe in this area:&lt;/P&gt;&lt;P&gt;Can I Debug and StepInto such code?&lt;/P&gt;&lt;P&gt;In code listing at the end of the article, is ControlEscape the only key combination being blocked?&lt;/P&gt;&lt;P&gt;Is ControlEscape the same as the Windows Key(ya know the one between Ctrl and Alt)?&lt;/P&gt;&lt;P&gt;If someone's got the time I would be estatic!&lt;img src='images/emotions/w00t.gif' height='20' width='20' border='0' title='w00t' align='absmiddle'&gt;&lt;/P&gt;&lt;P&gt;TIA&lt;/P&gt;</description><pubDate>Thu, 19 Aug 2004 11:58:30 GMT</pubDate><dc:creator>TallOne</dc:creator></item></channel></rss>
