Detecting Alt-F4 from hook

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;
moonriseAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
intheConnect With a Mentor Commented:
 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
 
ahalyaCommented:
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
 
ahalyaCommented:
oops, my Buf[vk_Menu] shd have been KeyState[VK_Menu]
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
ahalyaCommented:
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
 
moonriseAuthor Commented:
Thank you ahalya. inthe has the answer I was really looking for.
0
 
moonriseAuthor Commented:
How would I detect the Shift status (to disable Shift F10)?
0
 
intheCommented:
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
 
moonriseAuthor Commented:
Thank you.
0
All Courses

From novice to tech pro — start learning today.