Solved

Disable Ctrl-Esc

Posted on 1998-10-13
6
1,091 Views
Last Modified: 2008-03-04
I need a way to disable the shortcut Ctrl-esc. I have ways to disable all system keys, but I'm not interested in disableling the other system keys, such as Alt-Tab

I must also be able to reenable them again !
0
Comment
Question by:carceri
  • 3
  • 2
6 Comments
 

Expert Comment

by:JPiispa
ID: 1342700
Put on your form keypreview = True

then

procedure TAsrekForm.FormKeyPress(Sender: TObject; var Key: Char);
begin
 If Key=#13 then
  if (Activecontrol is TDBEdit) or (Activecontrol is TEdit) then
  begin
   Key:=#0;
   Perform(WM_NextDlgCtl, 0, 0);
  end
end;

This one makes Enter key look like Tab key. Now you just have to look if CTRL and Esc has been presses and put it Key:=#0;

Enabling/disablign like this
if prevent then Key:=#0;

where prevent is boolean variable.


0
 
LVL 1

Expert Comment

by:Roadrunner100598
ID: 1342701
Does this really work?

I think windows will intercept the shortcut before your form gets it.
This code should not work...!
0
 
LVL 1

Expert Comment

by:Roadrunner100598
ID: 1342702
Hello carceri,

that's a good question... gave me two hours of fun with API and hooks...

After playing with some API functions I finally have a solution that seems to work on my system (NT4). It involves using a hook function and intercepting via WH_CBT the WM_SYSCOMMAND only for the ProgMan window.

I will mail in the code as well, if you need it...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:carceri
ID: 1342703
Well... thanks JPiispa, but as Roadrunner says, Windows will intercept the shortcut before the form gets it.

And to Roadrunner: Yes I had the feeling that it needed some API coding. If you have some code, I'll would appreciate it a lot if you could mail it in as an answer here, so others can benefit from it as well

Thanks
0
 
LVL 1

Accepted Solution

by:
Roadrunner100598 earned 70 total points
ID: 1342704
Hello carceri,

here it comes...
----------------------------------------------------
library HookDll;

{$C FIXED PERMANENT PRELOAD}

uses
  WinProcs,
  SysUtils;

const
  hHookCBT : THandle = 0;

function CBTHookFunc(nCode: Integer; wparam: WPARAM; lparam: LPARAM): LRESULT stdcall;
begin
  if nCode=HCBT_SYSCOMMAND then begin
    messagebeep(-1);
    Result:=1; { removes message }
    end
  else
    { call next hook in chain }
    Result:=CallNextHookEx(hHookCBT, nCode, wParam, lParam);
end;

procedure InstallCBTHook; EXPORT;
var
  hLib : THandle;
  hProgMan : HWnd;
begin
  hLib:=GetModuleHandle('HookDll');
  if (hHookCBT=0) then begin
    hProgMan:=FindWindow('Progman', NIL);
    hHookCBT:=SetWindowsHookEx(WH_CBT, @CBTHookFunc, hLib,
                               GetWindowThreadProcessId(hProgMan, nil));
  end;
end;

procedure RemoveCBTHook; EXPORT;
begin
  if (hHookCBT<>0) then begin
    UnhookWindowsHookEx(hHookCBT);
    hHookCBT:=0;
  end;
end;

EXPORTS
  InstallCBTHook,
  RemoveCBTHook;

end.
----------------------------------------------------

Use this DLL within your program. InstallCBTHook enables the hook function.
All messages to the ProgMan class (I hope that classname stayed the same for Win95/98) are intercepted and if the message was a WM_SYSCOMMAND it will not be handed on to the ProgMan Window.

Therefore the ctrl-ESC and [Win95] shortcuts are disabled, but taskswitching via alt-TAB or the mouse still works.

If anyone has additional information about the PrgMan-class please comment.


Roadrunner
0
 

Author Comment

by:carceri
ID: 1342705
Thanks, that was just what I needed !
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now