3

How do I trap Windows key, Alt+Tab, and Ctrl+Alt+Delete in a Windows application using C#?

Ilmari Karonen
  • 49,047
  • 9
  • 93
  • 153
Suriyan Suresh
  • 2,964
  • 14
  • 51
  • 80
  • Duplicates: http://stackoverflow.com/questions/1292165/how-to-trap-the-keyboard-strokes-on-a-c-win-forms-application-ctrl-alt-del http://stackoverflow.com/questions/886076/how-can-i-intercept-all-key-events-including-ctrlaltdel-and-ctrltab – dtb Aug 28 '09 at 12:28
  • 6
    Yeah, but the original questions didn't use the cool `` tags! – P Daddy Aug 28 '09 at 12:43
  • 2
    I would recommend that you DON'T do this, if at all possible. When I press those keys, I'm expecting certain behavior, and if an application that I'm using prevented that behavior, I'd be upset. – Matt Grande Aug 28 '09 at 12:53
  • 5
    @Matt Grande: Sometimes what is required is not what the user wants. For instance, this exact behavior is often required for kiosk software. – P Daddy Aug 28 '09 at 12:59

5 Answers5

5

You can capture Ctrl-Alt-Delete. But you need to implement your own GINA dll which is loaded by Winlogon.

You'll need to code this up in C or C++ as it needs to be a native DLL.

Jan Bannister
  • 4,859
  • 8
  • 38
  • 45
4

As Jan stated, you can't capture CTRL-ALT-DEL without writing your own GINA.

For the Windows or ALT-TAB keys, you can look at these for help:

Capturing Keystrokes without Focus (SO near-duplicate)

How To Set A Windows Hook

Hooks (low-level, but will explain what you need for the P/Invoke)

Community
  • 1
  • 1
Erich Mirabal
  • 9,860
  • 3
  • 34
  • 39
1

Some Remote Management Software and Virtual Machines do this. If you press [CTRL]+[ALT]+[DEL] the specific Windows Dialog will still opens, but the Application also displays, that you have pressed [CTRL]+[ALT]+[DEL] and probably wanted it t become effective on the Target Machine and not your host. It seams rather easy to capture these keys, but cancelling the Event may be harder.

AyrA
  • 11
  • 1
1

Almost by definition, you can't "trap" ctrl-alt-delete.

unwind
  • 391,730
  • 64
  • 469
  • 606
1

AFAIK Ctrl + Alt + Delete cannot be captured using an application.

See this question to get some more idea: How to trap the keyboard strokes on a c# win forms application (CTRl + alt +Del)

Community
  • 1
  • 1
Shoban
  • 22,920
  • 8
  • 63
  • 107