Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to minimize an application by pressing [ALT] [TAB] Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
24-Feb-04
Category
Others
Language
Delphi 3.x
Views
136
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I would like to be able to minimize my application if the user presses [ALT] + 
[TAB]. Will I need to hook the keyboard for this? There is lot of code around to 
disable [ALT] [TAB] but nothing to detect it.

Answer:

This works on WinNT SP3+, Win2K and WinXP:

1   { ... }
2   var
3     FHook: HHook = 0;
4   
5   const
6     WH_KEYBOARD_LL = 13;
7     LLKHF_ALTDOWN = KF_ALTDOWN shr 8;
8   
9   type
10    tagKBDLLHOOKSTRUCT = packed record
11      vkCode: DWord;
12      scanCode: DWord;
13      flags: DWord;
14      time: DWord;
15      dwExtraInfo: PDWord;
16    end;
17    TKBDLLHOOKSTRUCT = tagKBDLLHOOKSTRUCT;
18    PKBDLLHOOKSTRUCT = ^TKBDLLHOOKSTRUCT;
19    { ... }
20  
21  function LowLevelKeyboardProc(HookCode: Longint; MessageParam: WParam;
22    StructParam: LParam): DWord; stdcall;
23  var
24    SwitchingTask: Boolean;
25    P: PKBDLLHOOKSTRUCT;
26  begin
27    SwitchingTask := False;
28    if (HookCode = HC_ACTION) then
29      case (MessageParam) of
30        WM_KEYDOWN, WM_SYSKEYDOWN, WM_KEYUP, WM_SYSKEYUP:
31          begin
32            P := PKBDLLHOOKSTRUCT(StructParam);
33            SwitchingTask := ((P.VKCode = VK_TAB) and (P.Flags and LLKHF_ALTDOWN <> 
34  0))
35              or
36              ((P.VKCode = VK_ESCAPE) and ((P.Flags and LLKHF_ALTDOWN) <> 0)) or
37              ((P.VKCode = VK_ESCAPE) and ((GetKeyState(VK_CONTROL)
38              and $8000) <> 0));
39          end;
40      end;
41    if SwitchingTask then
42    begin
43      {If you want to disable task switch just uncomment next two lines}
44       // Result := 1;
45       // Exit;
46      {If not, put your code here...}
47      Application.Minimize;
48    end;
49    Result := CallNextHookEx(0, HookCode, MessageParam, StructParam);
50  end;
51  
52  procedure SetHook;
53  begin
54    FHook := SetWindowsHookEx(WH_KEYBOARD_LL, @LowLevelKeyboardProc, Hinstance, 0);
55  end;
56  
57  procedure UnHook;
58  begin
59    if FHook > 0 then
60      UnHookWindowsHookEx(FHook);
61  end;
62  
63  procedure TMainForm.FormCreate(Sender: TObject);
64  begin
65    SetHook;
66  end;
67  
68  procedure TMainForm.FormDestroy(Sender: TObject);
69  begin
70    UnHook;
71  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC