Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Disabiling Alt-Tab

Posted on 2003-11-06
3
Medium Priority
?
297 Views
Last Modified: 2010-04-05
Hey,

How would I disable Alt-Tab key function?

Cheers
0
Comment
Question by:computerprogramer
[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 Comments
 
LVL 2

Expert Comment

by:gangsterboss
ID: 9698089
this disables all windows keys even once the program is closed

uses winprocs;
procedure TForm1.FormCreate(Sender: TObject);
var
   Dummy : integer;
begin
  Dummy := 0;
  SystemParametersInfo( SPI_SCREENSAVERRUNNING, 1, @Dummy, 0);
end;

if u would like to get them working its exactly the same code but replace the 1 with a 0

var
   Dummy : integer;
begin
  Dummy := 0;
  SystemParametersInfo( SPI_SCREENSAVERRUNNING, 0, @Dummy, 0);
end;
0
 
LVL 5

Accepted Solution

by:
snehanshu earned 80 total points
ID: 9698244
SPI_SCREENSAVERRUNNING would not work under win NT.
You can achieve this blocking using a "Keyboard Hook". A hook can be implemented using a DLL, but you could also set a hook within your program wiyhout a DLL.
Here's a code that blocks Alt-Tab when you press one button, and stops blocking Alt-Tab when you press the other button.
It can provide other functionalities if you uncomment some code in KeyBoardProc.
enjoy...

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;
const
  WH_KEYBOARD_LL = 13;
  LLKHF_EXTENDED = $01;
  LLKHF_INJECTED = $10;
  LLKHF_ALTDOWN  = $20;
  LLKHF_UP       = $80;

type
  TForm1 = class(TForm)
    BlockBtn: TButton;
    ReleaseBtn: TButton;

    procedure BlockBtnClick(Sender: TObject);
    procedure ReleaseBtnClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);  private
    procedure LockKeyboard; stdcall;
    procedure UnlockKeyboard; stdcall;
    { Private declarations }
  public
    { Public declarations }
  end;
 TKBDLLHOOKSTRUCT = packed record
   vkCode:      DWORD;
   scanCode:    DWORD;
   flags:       DWORD;
   time:        DWORD;
   dwExtraInfo: DWORD;
 end;
 PKBDLLHOOKSTRUCT = ^TKBDLLHOOKSTRUCT;
var
  Form1: TForm1;
  hKbdProc: HHOOK;


implementation

{$R *.DFM}

{ TForm1 }

function KeyBoardProc(iCode: Integer; wParam, lParam: LongInt): LongInt; stdcall;
var
  KeyData: TKBDLLHOOKSTRUCT;
  bIgnore: Boolean;
begin
  bIgnore := False;
  if iCode = HC_ACTION then
  begin
    KeyData := PKBDLLHOOKSTRUCT(lParam)^;
    with KeyData do
    begin
      // Block Control-Escape
//      if (vkCode = VK_ESCAPE) and ((GetAsyncKeyState(VK_CONTROL) and $8000) <> 0) then
//        bIgnore := True;
      // Block Control-Tab
//      if (vkCode = VK_TAB) and ((GetAsyncKeyState(VK_CONTROL) and $8000) <> 0) then
//        bIgnore := True;
      // Block Alt-Tab
      if (vkCode = VK_TAB) and ((flags and LLKHF_ALTDOWN) <> 0) then
        bIgnore := True;
      // Block Alt-Escape
//      if (vkCode = VK_ESCAPE) and ((flags and LLKHF_ALTDOWN) <> 0) then
//        bIgnore := True;
     // Block Left/Right Windows key
//      if KeyData.vkCode in [VK_LWIN, VK_RWIN] then
//        bIgnore := True;
      // Block Control-F4
//      if (vkCode = VK_F4) and ((GetAsyncKeyState(VK_CONTROL) and $8000) <> 0) then
//        bIgnore := True;
      // Block Alt-F4
//      if (vkCode = VK_F4) and ((flags and LLKHF_ALTDOWN) <> 0) then
//        bIgnore := True;
    end;
  end;
  if bIgnore then
    Result := 1
  else
    Result := CallNextHookEx(hKbdProc, iCode, wParam, lParam);
end;

procedure TForm1.LockKeyboard;
begin
  hKbdProc := SetWindowsHookEx(WH_KEYBOARD_LL, KeyBoardProc, HInstance, 0);
end;

procedure TForm1.UnlockKeyboard;
begin
  if hKbdProc <> 0 then
  begin
    UnHookWindowsHookEx(hKbdProc);
    hKbdProc := 0;
  end;
end;

procedure TForm1.BlockBtnClick(Sender: TObject);
begin
  LockKeyboard;
end;

procedure TForm1.ReleaseBtnClick(Sender: TObject);
begin
  UnlockKeyboard;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  UnlockKeyboard;
end;

end.
0
 

Expert Comment

by:huiyue
ID: 9699769
Yes,just use keyboard Hook
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

664 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