在UWP运行时禁用Windows键

时间:2016-12-20 15:43:32

标签: c# uwp

我正在构建一个通用的Windows应用程序,需要锁定桌面,以便用户无法逃脱程序。所以我需要暂时禁用Windows键和ctrl + alt + del。

我能够像这样添加一个事件处理程序:

Window.Current.CoreWindow.KeyDown += (s, e) => 
{
    if(e.VirtualKey == VirtualKey.LeftWindows || e.VirtualKey == VirtualKey.RightWindows)
    {
        e.Handled = true;
    }
}

但是按键事件仍然会发生。

我还发现了一种使用我认为是来自user32 lib的Windows挂钩的方法。

[DllImport("user32", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool RegisterHotKey(IntPtr hwnd, int id, uint fsModifiers, uint vk);
[DllImport("user32", SetLastError = true)]
public static extern int UnregisterHotKey(IntPtr hwnd, int id);
[DllImport("kernel32", SetLastError = true)]

我找到了一些示例代码here,但我想我必须为简单的Windows按键调整它。

Windows钩子方法(在示例链接中使用)是否可以使用?

1 个答案:

答案 0 :(得分:2)

我认为Kiosk apps for assigned access非常接近您的要求。本文档介绍了如何实现自助服务终端应用。您可以使用Lock框架和分配的访问权限来创建自助服务终端应用,使用户可以与设备上的单个应用进行互动。

Set up a kiosk on Windows 10 Pro, Enterprise, or Education供您参考。