[英]wpf Stop ctrl+Alt+del and windows button using C#
how to disable ctrl + Alt + del and windows button using C# with wpf ??如何使用带有 wpf 的 C# 禁用ctrl + Alt + del和 windows 按钮?
I tried to use some events form events like key down but fail.我尝试使用一些事件形式的事件,如按键但失败。
It isn't possible to disable the shortcut for Ctrl - Alt - Del specifically, this is because the Ctrl - Alt - Del combo is a deeply baked system call.无法专门禁用Ctrl - Alt - Del的快捷方式,这是因为Ctrl - Alt - Del组合是一个深度烘焙的系统调用。
However it is possible to filter them separately, so you can prevent the other shortcuts with these keys.但是,可以单独过滤它们,因此您可以使用这些键阻止其他快捷方式。 To do this you need to hook into the OS events:
为此,您需要挂钩操作系统事件:
this hooks onto the system events.这与系统事件挂钩。
private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SetWindowsHookEx(int id, LowLevelKeyboardProc callback, IntPtr hMod, uint dwThreadId);
if you set the id to 13 it will hook onto the keyboard inputs.如果您将 id 设置为 13,它将连接到键盘输入。
in the callback you need several things:在回调中,您需要做几件事:
[StructLayout(LayoutKind.Sequential)]
private struct KBDLLHOOKSTRUCT
{
public readonly Keys key;
private readonly int scanCode;
private readonly int flags;
private readonly int time;
private readonly IntPtr extra;
}
this struct is required to read the actual keys in c#.需要这个结构来读取 c# 中的实际键。
this can be used by giving the delegate a function like:这可以通过为委托提供如下函数来使用:
private static IntPtr CaptureKey(int nCode, IntPtr wp, IntPtr lp)
{
if (nCode < 0) return (IntPtr) 1; //CallNextHookEx(_ptrHook, nCode, wp, lp);
KBDLLHOOKSTRUCT objKeyInfo = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lp, typeof(KBDLLHOOKSTRUCT));
if(objKeyInfo.key == /*some key*/){
// do something
}
}
when using this you can get the key from objKeyInfo.key
使用它时,您可以从
objKeyInfo.key
获取密钥
for more background info about the Ctrl
- Alt
- Del
combo: Is there any method to disable logoff,lock and taskmanager in ctrl+alt+del in C#有关
Ctrl
- Alt
- Del
组合的更多背景信息: 是否有任何方法可以在 C# 中的 ctrl+alt+del 中禁用注销、锁定和任务管理器
Tamas Piros 写了一篇关于该主题的不错的文章http://tamas.io/c-disable-ctrl-alt-del-alt-tab-alt-f4-start-menu-and-so-on/ 也应该在 WPF 中工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.