Solved

Disable Ctrl-Esc

Posted on 1998-10-13
6
1,094 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
[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
  • 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
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!

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Create Database on Android via Delphi dbExpress 3 129
Delphi 2 77
How to insert .png images to TClientDataSet .cds file? 2 70
Delphi, TImage, Png 2 19
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

735 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