对于触屏的软件来说,我们调出系统键盘以后,我们不想用户回到桌面,这时候我们就需要屏蔽windows键,

 #region 屏蔽WIN功能键
public delegate int HookProc(int nCode, int wParam, IntPtr lParam);
private static int hHook = ;
public const int WH_KEYBOARD_LL = ; //LowLevel键盘截获,如果是WH_KEYBOARD=2,并不能对系统键盘截取,会在你截取之前获得键盘。
private static HookProc KeyBoardHookProcedure;
//键盘Hook结构函数
[StructLayout(LayoutKind.Sequential)]
public class KeyBoardHookStruct
{
public int vkCode;
public int scanCode;
public int flags;
public int time;
public int dwExtraInfo;
} //设置钩子
[DllImport("user32.dll")]
public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId); [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
//抽掉钩子
public static extern bool UnhookWindowsHookEx(int idHook); [DllImport("user32.dll")]
//调用下一个钩子
public static extern int CallNextHookEx(int idHook, int nCode, int wParam, IntPtr lParam); [DllImport("kernel32.dll")]
public static extern int GetCurrentThreadId(); [DllImport("kernel32.dll")]
public static extern IntPtr GetModuleHandle(string name); public static void Hook_Start()
{
// 安装键盘钩子
if (hHook == )
{
KeyBoardHookProcedure = new HookProc(KeyBoardHookProc);
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyBoardHookProcedure,
GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), );
//如果设置钩子失败.
if (hHook == )
{
Hook_Clear();
}
}
} //取消钩子事件
public static void Hook_Clear()
{
bool retKeyboard = true;
if (hHook != )
{
retKeyboard = UnhookWindowsHookEx(hHook);
hHook = ;
}
//如果去掉钩子失败.
if (!retKeyboard) throw new Exception("UnhookWindowsHookEx failed.");
} //这里可以添加自己想要的信息处理
private static int KeyBoardHookProc(int nCode, int wParam, IntPtr lParam)
{
if (nCode >= )
{
KeyBoardHookStruct kbh = (KeyBoardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyBoardHookStruct)); if (kbh.vkCode == ) // 截获左win(开始菜单键)
{
return ;
} if (kbh.vkCode == )// 截获右win
{
return ;
} if (kbh.vkCode == (int)Keys.Escape && (int)Control.ModifierKeys == (int)Keys.Control) //截获Ctrl+Esc
{
return ;
} if (kbh.vkCode == (int)Keys.F4 && (int)Control.ModifierKeys == (int)Keys.Alt) //截获alt+f4
{
return ;
} if (kbh.vkCode == (int)Keys.Tab && (int)Control.ModifierKeys == (int)Keys.Alt) //截获alt+tab
{
return ;
} if (kbh.vkCode == (int)Keys.Escape && (int)Control.ModifierKeys == (int)Keys.Control + (int)Keys.Shift) //截获Ctrl+Shift+Esc
{
return ;
} if (kbh.vkCode == (int)Keys.Space && (int)Control.ModifierKeys == (int)Keys.Alt) //截获alt+空格
{
return ;
} if (kbh.vkCode == ) //截获F1
{
return ;
} if ((int)Control.ModifierKeys == (int)Keys.Control + (int)Keys.Alt + (int)Keys.Delete) //截获Ctrl+Alt+Delete
{
return ;
} if ((int)Control.ModifierKeys == (int)Keys.Control + (int)Keys.Shift) //截获Ctrl+Shift
{
return ;
} if (kbh.vkCode == (int)Keys.Space && (int)Control.ModifierKeys == (int)Keys.Control + (int)Keys.Alt) //截获Ctrl+Alt+空格
{
return ;
}
} return CallNextHookEx(hHook, nCode, wParam, lParam);
}
public static void TaskMgrLocking(bool bLock)
{
if (bLock)
{
try
{
RegistryKey r = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", true);
r.SetValue("DisableTaskmgr", ""); //屏蔽任务管理器
}
catch
{
RegistryKey r = Registry.CurrentUser.CreateSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System");
r.SetValue("DisableTaskmgr", "");
}
}
else
{
Registry.CurrentUser.DeleteSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System");
}
}
#endregion // 调用,这个需要放在主窗体的load方法中
//private void Load(object sender, EventArgs e)
//{
// Hook_Start();
//} //卸载
private void FormClosing(object sender, FormClosingEventArgs e)
{
Hook_Clear();
}

C# 屏蔽windows功能键的更多相关文章

  1. 屏蔽windows快捷键的方法

    using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using ...

  2. MFC屏蔽 WindowS按键

    LRESULT CALLBACK LowLevelKeyboardPorc(int nCode,WPARAM wParam,LPARAM lParam)//屏蔽按键的真正实现方法{ BOOL fEat ...

  3. C# 通过Hook的方法 屏蔽快捷键

     #region 屏蔽Windows功能键(快捷键)         public delegate int HookProc(int nCode, int wParam, IntPtr lParam ...

  4. 微软发布屏蔽Win10升级的官方办法

    微软发布屏蔽Win10升级的官方办法 导读 微软似乎从来就没有像现在这么焦燥过,当然了,攸关生死,他要还是能"蛋"定得住,那才真叫怪了.你看,为了推广Windows 10,一向傲娇 ...

  5. Windows开机登录认证与Gina DLL

    Windows的开机密码认证模块一般是由Gina DLL完成的.在NT/2000中交互式的登陆支持是由WinLogon调用GINA DLL实现的,GINA DLL提供了一个交互式的界面为用户登陆提供认 ...

  6. Windows界面设计标准

    Windows界面设计标准..- Windows界面设计标准 Windows 界面设计标准 1. 易用性 界面元素的名称.标签应该易懂,用词准确,避免使用模楞两可的字眼,要与同一界面上的其他元素易于区 ...

  7. windows系统快捷键

    1.我的键盘:windows键的开启,需要按住FN键+windows键. 2.windows键 + E,表示打开我的电脑. 3.windows键 + R,打开windows的命令行窗口. 4.wind ...

  8. Windows远程桌面和360

    Windows的远程桌面输错了一次密码, 然后就怎么都连接不上了, 查了半天发现 傻缺360会默认屏蔽Windows的远程桌面和数据库连接..... 大家没事都卸载了360吧

  9. C#屏蔽Alt+F4组合键

    在开发的软件不希望用户关闭的情况下,或者我们不想用户回到桌面,这时候我们就需要屏蔽windows键,或者Alt + F4 键等. //1.将窗体的属性KeyPrieview设置为true //keyp ...

随机推荐

  1. value power two

    /** *topPower2 use to set unsigned int to power of two *@param value input value *@return return the ...

  2. DesUtils工具类

    public final class DesUtils { private static final String DES = "DES"; private static fina ...

  3. 《Think Python》第16章学习笔记

    目录 <Think Python>第16章学习笔记 16.1 Time 16.2 纯函数(Pure functions) 16.3 修改器(Modifiers) 16.4 原型 vs. 方 ...

  4. oracle 数据库添加Java方法

    create or replace and compile java source named "Bitconverter" aspublic class Bitconverter ...

  5. Tomcat源码分析——请求原理分析(上)

    前言 谈起Tomcat的诞生,最早可以追溯到1995年.近20年来,Tomcat始终是使用最广泛的Web服务器,由于其使用Java语言开发,所以广为Java程序员所熟悉.很多人早期的J2EE项目,由程 ...

  6. ASP.NET MVC* 采用Unity依赖注入Controller

    Unity是微软Patterns & Practices团队所开发的一个轻量级的,并且可扩展的依赖注入(Dependency Injection)容器,它支持常用的三种依赖注入方式:构造器注入 ...

  7. [转]flash.net.Socket

    本文转自:http://designstacks.net/actionscript-3-new-capabilities http://help.adobe.com/en_US/ActionScrip ...

  8. 浅谈.net MVC

    大学毕业对MVC的概念还不是很清晰,总觉得MVC是和三层一样的,是同一级别的架构.其实不然,三层架构是:BLL(业务逻辑层),DAL(数据库访问层),UI(页面显示层),而MVC仅仅是属于三层架构UI ...

  9. centos开启防火墙端口

    1. 查看已打开的端口 # netstat -anp 2. 查看想开的端口是否已开 # firewall-cmd --query-port=80/tcp 若此提示 FirewallD is not r ...

  10. 【SSH网上商城项目实战14】商城首页UI的设计

    转自:https://blog.csdn.net/eson_15/article/details/51373403 前面我们利用EasyUI和SSH搭建好了后台的基本框架,做好了后台的基本功能,包括对 ...