TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Keith Bennett
from: Mark Shumway
date: 1994-08-16 10:39:04
subject: Possible to trap Ctrl-Alt-Del or NumLock?

KB> Is there any way to trap the Ctrl-Alt-Del key sequence?  This is 

Yes, the following code will do it.  Of course, although OS/2 handles CAD
quite well, there could be many application-specific reasons why this would
be desirable.  I can imagine scenarios involving real time process control,
monitoring, security and many more.  Assuming that the system cabinet is
secured and locked-away, a redundant power supply has been isolated and
backed up on an UPS, and for application-specific reasons (not to mention
security, as it may be in a public area) ... you simply cannot have anyone
casually walking by the keyboard and offering a three finger salute.  We're
talking a very sophisticated turnkey application here, not your simple
shareware mail reader.

Anyway, FWIW the following code was snipped from the FidoNet OS2PROG echo
on 6/1/93, in a response to Kenneth Roach who had the exact concerns listed
above. The code works as a toggle. If you run the code once, it will
disable CAD. If you run it again, it will enable CAD. As an extra bonus, it
will also dump your session manager hot keys.

Originally posted here by  Kim Kruse Hansen, I've compiled and tested this
with Watcom v10. 

---------8<------------Cut-Here----------------8<-------------

#define INCL_DOS
#include 
#include 
#include 
#include 
#include 

#pragma pack(1)

typedef struct _SESMGRHOTKEY
                {
                        USHORT State;
                        UCHAR Make;
                        UCHAR  Break;
                        USHORT Hot;
                } SESMGRHOTKEY, *PSESMGRHOTKEY;

#pragma pack()

HFILE hRead;

ULONG OpenKBD()

{
ULONG    lastrc;
PCHAR    fname="KBD$";
ULONG    action=0;
ULONG    filesize=0;
ULONG    fileattributes=FILE_NORMAL;
ULONG    openflag=OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS;
ULONG    openmode=OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE;
PEAOP2   eabuf=NULL;

  lastrc=DosOpen(fname,
                &hRead,
                &action,                // action if open ok
                filesize,               // file size
                fileattributes,         // file attributes (if created)
                openflag,               //
                openmode ,              // sharingmode
                eabuf);                 // ea buffer,
  return lastrc;
}

void DumpKeys(PSESMGRHOTKEY pKey,ULONG ulCnt)

{
  ULONG f;
  for (f=0;fState);
    printf("make =%2.2x\n",pKey->Make);
    printf("break =%2.2x\n",pKey->Break);
    printf("Hot =%4.4x\n",pKey->Hot);
    printf("-------------------------\n");
    pKey++;
  }
}


void DisableCAD()

{
ULONG lastrc;
ULONG parminout=0;
ULONG datainout=0;
SESMGRHOTKEY key;


      memset(&key,0,sizeof(key));
      key.Hot=-1;   // <<<< -- this is the important one
      parminout=sizeof(SESMGRHOTKEY);
      lastrc=DosDevIOCtl(hRead,           // disable cad
                          4,
                          0x56,
                          &key,
                          sizeof(SESMGRHOTKEY),
                          &parminout,
                          NULL,
                          0,
                          &datainout);
      printf("Disable %d\n",lastrc);
}

ULONG QuerySessionMgrHotKey()

{
ULONG lastrc;
USHORT parm=0;
ULONG parminout=0;
ULONG datainout=0;

  lastrc=DosDevIOCtl(hRead,
                       4,
                       0x76,
                        &parm,
                        sizeof(USHORT),
                        &parminout,
                        NULL,
                        0,
                        &datainout);
  if (!lastrc)
  {
    PSESMGRHOTKEY pKey;
    ULONG ulLen=sizeof(SESMGRHOTKEY)*parm;

    pKey=(PSESMGRHOTKEY) malloc(ulLen);
    memset(pKey,0x0,ulLen);

    parm=1;
    lastrc=DosDevIOCtl(hRead,           // query actual hot keys
                          4,
                          0x76,
                          &parm,
                          sizeof(USHORT),
                          &parminout,
                          pKey,
                          ulLen,
                          &datainout);
    if (!lastrc)
    {
      DumpKeys(pKey,parm);
    }
  }
  return lastrc;
}

int main(int argc,char *argv[],char *envp[])

{
  if (!OpenKBD())
  {
    QuerySessionMgrHotKey();  // dump of hot keys
    DisableCAD();                       // toggle Ctrl-Alt-Del
    DosClose(hRead);
  }
  return 0;
}

---------8<------------Cut-Here----------------8<-------------

Have fun! 

--- Sqed/32 0.96/r15003

* Origin: River of Swans, an OS/2 BBS * (913) 242-1204 * (1:2801/20)
SEEN-BY: 12/2442 54/54 620/243 624/50 632/348 640/820 690/660 711/409 410 413
SEEN-BY: 711/430 807 808 809 934 712/353 623 713/888 800/1
@PATH: 2801/1 280/1 396/1 3615/50 229/2 12/2442 711/409 54/54 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.