473,416 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

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 43901
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
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
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
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
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
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
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
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
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
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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...
0
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.