?
Solved

Detecting Alt-F4 from hook

Posted on 2000-03-09
8
Medium Priority
?
730 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
Industry Leaders: 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 800 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month7 days, 19 hours left to enroll

765 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