473,506 Members | 16,951 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Disable ALT+F4; CTRL+ALT+DEL; CTRL+ESC;ALT+TAB

Hy,

i have an app and i must disable this combination: ALT+F4;
CTRL+ALT+DEL; CTRL+ESC;ALT+TAB like this:

i find something on Internet and i can block ALT+F4

protected override System.Boolean
ProcessCmdKey(ref System.Windows.Forms.Message
msg,System.Windows.Forms.Keys keyData)
{
if ((msg.Msg == 0x104) && (((int)
msg.LParam) == 0x203e0001))
return true;
return false;
}

pls help, how can i block the rest of keys.
Stefanelus
Nov 15 '05 #1
3 43926
Hi Stefan,

You need to P/Invoke SetWindowsHookEx:

I got this code from somewhere but I did not test it at the end.

public class Win32Hook
{

[DllImport("kernel32")]
public static extern int GetCurrentThreadId();

[DllImport( "user32",
CharSet=CharSet.Auto,CallingConvention=CallingConv ention.StdCall)]
public static extern int SetWindowsHookEx(
HookType idHook,
HOOKPROC lpfn,
int hmod,
int dwThreadId);

public enum HookType
{
WH_KEYBOARD = 2
}

public delegate int HOOKPROC(int nCode, int wParam, int lParam);

public void SetHook()
{
// set the keyboard hook
SetWindowsHookEx(HookType.WH_KEYBOARD,
new HOOKPROC(this.MyKeyboardProc),
0,
GetCurrentThreadId());
}

public int MyKeyboardProc(int nCode, int wParam, int lParam)
{
//Perform your process
return 0;
}
}
And then you can install the hook procedure by the following code:

Win32Hook hook = new Win32Hook();
hook.SetHook();

In the MyKeyboardProc function, you can determine which key is pressed by
the wParam parameter. You also can identify the key is pressed or released
by the lParam parameter. Then you can set a flag when the Ctrl is pressed
and set another flag when the Alt is pressed. When both flag are set, stop
the program.
Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Stefan" <st****@inwww.ltd.uk> wrote in message
news:5e****************************@phx.gbl...
Hy,

i have an app and i must disable this combination: ALT+F4;
CTRL+ALT+DEL; CTRL+ESC;ALT+TAB like this:

i find something on Internet and i can block ALT+F4

protected override System.Boolean
ProcessCmdKey(ref System.Windows.Forms.Message
msg,System.Windows.Forms.Keys keyData)
{
if ((msg.Msg == 0x104) && (((int)
msg.LParam) == 0x203e0001))
return true;
return false;
}

pls help, how can i block the rest of keys.
Stefanelus

Nov 15 '05 #2
Hi Stefan,

"Stefan" <st****@inwww.ltd.uk> wrote in message
news:5e****************************@phx.gbl...
Hy,

i have an app and i must disable this combination: ALT+F4;
CTRL+ALT+DEL; CTRL+ESC;ALT+TAB like this:

i find something on Internet and i can block ALT+F4


I don't know how far you'll get blocking the rest of them, but blocking
the CTRL+ALT+DEL sequence (esp. on NT, 2K, XP) is practically impossible.
Okay, there's this thing called a GINA dll, but trust me, you don't want to
go there.

The reason for this is security. Just about any application can put up a
set of dialogs that look like the standard secure windows login dialog(s).
Pressing CTRL+ALT+DEL is the guaranteed way to get to the "real" login
screen without worrying that you're about to give your user name/password to
a java applet, etc.

Regards,
Dan
Nov 15 '05 #3


Hy Ignacio,

thx for your help, i find something on internet:

private delegate int LowLevelKeyboardProcDelegate(int nCode, int
wParam, ref KBDLLHOOKSTRUCT lParam);
[ DllImport( "user32.dll", EntryPoint="SetWindowsHookExA",
CharSet=CharSet.Ansi )]
private static extern int SetWindowsHookEx(int idHook ,
LowLevelKeyboardProcDelegate lpfn, int hMod , int dwThreadId);
[ DllImport( "user32.dll", EntryPoint="UnHookWindowsHookEx",
CharSet=CharSet.Ansi )]
private static extern int UnHookWindowsEx(int hHook);
[ DllImport( "user32.dll", EntryPoint="CallNextHookEx",
CharSet=CharSet.Ansi )]
private static extern int CallNextHookEx(int hHook,int nCode, int
wParam, ref KBDLLHOOKSTRUCT lParam);
const int WH_KEYBOARD_LL = 13;
public struct KBDLLHOOKSTRUCT
{
public int vkCode;
int scanCode;
public int flags;
int time;
int dwExtraInfo;
}
private int intLLKey;
private KBDLLHOOKSTRUCT lParam;

private int LowLevelKeyboardProc(int nCode,int wParam,ref
KBDLLHOOKSTRUCT lParam)
{
bool blnEat = false;
switch (wParam)
{
case 256:
case 257:
case 260:
case 261:
//Alt+Tab, Alt+Esc, Ctrl+Esc, Windows Key
if(((lParam.vkCode == 9) && (lParam.flags == 32)) ||
((lParam.vkCode == 27) && (lParam.flags == 32)) || ((lParam.vkCode ==
27) && (lParam.flags == 0)) || ((lParam.vkCode == 91) && (lParam.flags
== 1)) || ((lParam.vkCode == 92) && (lParam.flags == 1)) || ((true) &&
(lParam.flags == 32)))
{
blnEat = true;
}
break;
}

if (blnEat)
return 1;
else return CallNextHookEx(0, nCode, wParam, ref lParam);

}
public void KeyboardHook(object sender, EventArgs e)
{
intLLKey = SetWindowsHookEx(WH_KEYBOARD_LL, new
LowLevelKeyboardProcDelegate(LowLevelKeyboardProc) ,
System.Runtime.InteropServices.Marshal.GetHINSTANC E(System.Reflection.As
sembly.GetExecutingAssembly().GetModules()[0]).ToInt32(),0);
}
Stefan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
9193
by: hugo27 | last post by:
hugo27 July 13, 2004 > >The teachy books and documentation I've read do not >mention the Escape key, but everytime I hit it during >runtime my programs go bananas. > >This relates to a larger...
3
5859
by: Joe | last post by:
Dear Friends, How do disable the Alt+Tab,Alt+F4,ctr+Alt+Delete ,Alt+esc,Ctrl+Esc keys through C# program? Can anybody give me a clue or sample code? Advance Thanks, Thanks, Joe
0
4488
by: Stefan | last post by:
Hy, a have an application and i must disable the follow combination of keys: ALT+F4 ALT+TAB CTRL+ALT+DEL CTRL+ESC. For ALT+F4 i can disable the conbination with: protected override...
3
3134
by: Mark | last post by:
Any Visual C++ source code available for disabling the following keys in windows 2000. Alt + Ctrl + Del Ctrl + Esc Windows Key to Remove task bar Function keys (or Alt + Function keys or Ctrl...
331
14679
by: Xah Lee | last post by:
http://xahlee.org/emacs/modernization.html ] The Modernization of Emacs ---------------------------------------- THE PROBLEM Emacs is a great editor. It is perhaps the most powerful and...
7
12525
by: bz | last post by:
Hi, I need an app to run in kiosk mode, so user will not have access to start menu and taskbar while the app is running I was able to hide / show the taskbar with trhe following code when...
10
8527
by: thupham | last post by:
Dear all friend, I want disable Ctl+Alt+Del; Ctrl+Esc; Ctrl+tab, Alt+Tab, Start button, ctrl+Alt+Del, lock all keys on the keyboard. Have you ever do it in C#. Help me. Thanks for all reply.
1
2653
hidash
by: hidash | last post by:
hi all, i want to disable the keys in keyboard for my webpage created using jsp. i need to make disable i) Alt+Tab ii) Alt+Esc iii) Ctrl+Tab ...
2
2561
by: Swan | last post by:
How can I restrict alt+tab and start menu from keyboard while program executing(VB)?I am posting what I tried-- form.frm Option Explicit Private Sub Form_Load() HookKeyboard End Sub...
0
7218
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7103
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7021
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4701
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.