🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #7403

About Keyboard hooking & KBDLLHOOKSTRUCT

#7403
From: Vladimir Stefanovic
Date: Thu, 03 Feb 2005 12:08
80 lines
3266 bytes
Hi,

Can someone please interpret me something about Keyboard
Hooking. When I press a key, is it true that the structure
KBDLLHOOKSTRUCT saved also the modifier (Alt, Shift, ...)
state? I need this because I want to SendMessage() to the
main app only when, for example Alt is pressed also.

I got to that conclusion from the API code I found (not for BCB),
but probably may work:

<quote>

   LRESULT CALLBACK LowLevelKeyboardProc (INT nCode, WPARAM wParam, LPARAM 
lParam)
   {
      KBDLLHOOKSTRUCT *pkbhs = (KBDLLHOOKSTRUCT *) lParam;
      BOOL bControlKeyDown = 0;
      switch (nCode)
      {
         case HC_ACTION:
         {
            bControlKeyDown = GetAsyncKeyState (VK_CONTROL) >> 
((sizeof(SHORT) * 8) - 1); // Disable CTRL+ESC
            if (pkbhs->vkCode == VK_ESCAPE && bControlKeyDown)
               return 1;
            // Disable ATL+TAB
            if (pkbhs->vkCode == VK_TAB && pkbhs->flags & LLKHF_ALTDOWN)
               return 1;
            // Disable ALT+ESC
            if (pkbhs->vkCode == VK_ESCAPE && pkbhs->flags & LLKHF_ALTDOWN)
               return 1;
            // Disable the WINDOWS key
            if (pkbhs->vkCode == VK_LWIN || pkbhs->vkCode == VK_RWIN)
               return 1;
            break;
         }
         default:
         break;
      }
      return CallNextHookEx (hHook, nCode, wParam, lParam);
   }

</quote>

What means 'return 1', and is there a way to extend my code (below)
to work with checking for Alt?


--- DLL ---
DWORD __stdcall CheckKey( int nCode, WORD wParam, LONG lParam )
{
   HWND ghAppWnd = FindWindow( "TDiMainForm", 0 );

   if ( ( nCode < 0 ) || ( nCode == HC_NOREMOVE ) )
     return CallNextHookEx( ghhookKB, nCode, wParam, lParam );

   // Skip if it's a repeat
   if ( lParam & 0x40000000 )
      return CallNextHookEx( ghhookKB, nCode, wParam, lParam );

   // Send *every* key information to the main window
   SendMessage( ghAppWnd, WM_KEYHOOK, 0, lParam );

   return CallNextHookEx( ghhookKB, nCode, wParam, lParam );
}

--- CPP --- (logging the keyboard activity to Memo1)
void __fastcall TDiMainForm::KeyHook( TMessage &Message )
{
   char HKey[80];
   GetKeyNameText( Message.LParam, HKey, 80 );

   Memo1->Lines->Add( AnsiString( HKey ) );
}


-- 
Best regards,
Vladimir Stefanovic 
Technical Details
Message-ID: <42021449@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,8625c090d856cce0,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Vladimir Stefanovic" <antivari@po.sbb.co.yu>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: About Keyboard hooking & KBDLLHOOKSTRUCT 
Date: Thu, 3 Feb 2005 13:08:49 +0100
Lines: 82
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 82.117.212.65
Message-ID: <42021449@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1107432521 82.117.212.65 (3 Feb 2005 04:08:41 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail