Solved

Detecting Alt-F4 from hook

Posted on 2000-03-09
8
728 Views
Last Modified: 2008-01-16
I already have a system wide hook to check keystroke (see below). I need to know when Alt F4 was pressed. What code do I need to add to the following code to check if Alt F4 was pressed?

function KEYBOARD_HookProc(nCode: Integer; WPARAM: wParam; LPARAM: lParam): LResult; stdcall;
begin
  if nCode >= 0 then
  begin
    PostMessage(rHookRec^.MainWindow, WM_User + 1, 555, 3);
    CallNextHookEx(rHookRec^.HookIDKEYBOARD, nCode, wParam, lParam);
    Result := 0;
  end
  else
    Result := CallNextHookEx(rHookRec^.HookIDKEYBOARD, nCode, wParam, lParam);
end;
0
Comment
Question by:moonrise
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 7

Expert Comment

by:ahalya
ID: 2603271
Well,  you can use the following to detect the "ALT" key. I'm not sure about F4 though.

var  KeyState : TKeyboardState;

GetKeyboardState(KeyState); //
AltDown := ((Buf[vk_Menu]    And 128) <> 0);
0
 
LVL 7

Expert Comment

by:ahalya
ID: 2603273
oops, my Buf[vk_Menu] shd have been KeyState[VK_Menu]
0
 
LVL 7

Expert Comment

by:ahalya
ID: 2603282
i think you can detect F4 also from the KeyBoardState:

The following shd word;


var  KeyState : TKeyboardState;
       AltDown, F4Down : boolean;


GetKeyboardState(KeyState); //
AltDown := ((KeyState[vk_Menu]    And 128) <> 0);
F4Down := ((KeyState[vk_F4]    And 128) <> 0);

If (AltDown and F4Down) then
   PostMessage(to your app...)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Accepted Solution

by:
inthe earned 200 total points
ID: 2603347
 if ((lParam AND (1 shl 29)) <> 0) and case wParam of      
    VK_F4 : then begin
   Alt&F4 := True;//Alt&F4 is global boolean.
                 end;
end;
0
 

Author Comment

by:moonrise
ID: 2603381
Thank you ahalya. inthe has the answer I was really looking for.
0
 

Author Comment

by:moonrise
ID: 2603401
How would I detect the Shift status (to disable Shift F10)?
0
 
LVL 17

Expert Comment

by:inthe
ID: 2606234
Hi
that would be something like:

 if (((GetKeyState(VK_SHIFT) AND (1 shl 15)) <> 0) and case wparam of VK_F10 :then begin
Shift&F10 := True; //boolean
  end;
end;
0
 

Author Comment

by:moonrise
ID: 2606782
Thank you.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question