Solved

Disable Ctrl-Esc

Posted on 1998-10-13
6
1,090 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

19 Experts available now in Live!

Get 1:1 Help Now