簡體   English   中英

wpf 使用 C# 停止 ctrl+Alt+del 和 windows 按鈕

[英]wpf Stop ctrl+Alt+del and windows button using C#

如何使用帶有 wpf 的 C# 禁用ctrl + Alt + del和 windows 按鈕?

我嘗試使用一些事件形式的事件,如按鍵但失敗。

無法專門禁用Ctrl - Alt - Del的快捷方式,這是因為Ctrl - Alt - Del組合是一個深度烘焙的系統調用。

但是,可以單獨過濾它們,因此您可以使用這些鍵阻止其他快捷方式。 為此,您需要掛鈎操作系統事件:


這與系統事件掛鈎。

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);

如果您將 id 設置為 13,它將連接到鍵盤輸入。


在回調中,您需要做幾件事:

[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;
}

需要這個結構來讀取 c# 中的實際鍵。

這可以通過為委托提供如下函數來使用:

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
    }
}

使用它時,您可以從objKeyInfo.key獲取密鑰

有關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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM