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^.Main Window, WM_User + 1, 555, 3);
CallNextHookEx(rHookRec^.H ookIDKEYBO ARD, nCode, wParam, lParam);
Result := 0;
end
else
Result := CallNextHookEx(rHookRec^.H ookIDKEYBO ARD, nCode, wParam, lParam);
end;
function KEYBOARD_HookProc(nCode: Integer; WPARAM: wParam; LPARAM: lParam): LResult; stdcall;
begin
if nCode >= 0 then
begin
PostMessage(rHookRec^.Main
CallNextHookEx(rHookRec^.H
Result := 0;
end
else
Result := CallNextHookEx(rHookRec^.H
end;
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...)
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you ahalya. inthe has the answer I was really looking for.
ASKER
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;
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;
ASKER
Thank you.
var KeyState : TKeyboardState;
GetKeyboardState(KeyState)
AltDown := ((Buf[vk_Menu] And 128) <> 0);