Link to home
Start Free TrialLog in
Avatar of moonrise
moonrise

asked on

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;
Avatar of ahalya
ahalya
Flag of Canada image

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);
oops, my Buf[vk_Menu] shd have been KeyState[VK_Menu]
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...)
ASKER CERTIFIED SOLUTION
Avatar of inthe
inthe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of moonrise
moonrise

ASKER

Thank you ahalya. inthe has the answer I was really looking for.
How would I detect the Shift status (to disable Shift F10)?
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;
Thank you.