Solved

Detecting Alt-F4 from hook

Posted on 2000-03-09
8
720 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now