C#编写的挂机锁代码
有没有C#编写的挂机锁代码有的话麻烦发送到qtwap@vip.qq.com要可以屏蔽按键的...
有没有C#编写的挂机锁代码 有的话麻烦发送到qtwap@ vip.qq.com 要可以屏蔽按键的
展开
展开全部
C# 挂机锁 可以用hook(钩子)去做 监听键盘的按键 并且kill任务管理器的进程 钩子具体实现需要委托。网上有挂机锁的源码。 追问: 都不可以用 回答: using System; using System.Windows.Forms; using System.Text; using System.Runtime.InteropServices; using System.Reflection; using System.IO; namespace HookLock { public class Hook { #region 私有变量 /// <summary> /// 键盘钩子句柄 /// </summary> private IntPtr m_pKeyboardHook = IntPtr.Zero; /// <summary> /// 钩子委托声明 /// </summary> /// <param name="nCode"></param> /// <param name="wParam"></param> /// <param name="lParam"></param> /// <returns></returns> public delegate int HookProc(int nCode, Int32 wParam, IntPtr lParam); /// <summary> /// 键盘钩子委托实例 /// </summary> /// <remarks> /// 不要试图省略此变量,否则将会导致 /// 激活 CallbackOnCollectedDelegate 托管调试助手 (MDA)。 /// 详细请参见MSDN中关于 CallbackOnCollectedDelegate 的描述 /// </remarks> private HookProc m_KeyboardHookProcedure; // 底层键盘钩子 public const int idHook = 13; /// <summary> /// 安装钩子 /// </summary> /// <param name="idHook"></param> /// <param name="lpfn"></param> /// <param name="hInstance"></param> /// <param name="threadId"></param> /// <returns></returns> [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall)] public static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr pInstance, int threadId); /// <summary> /// 卸载钩子 /// </summary> /// <param name="idHook"></param> /// <returns></returns> [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall)] public static extern bool UnhookWindowsHookEx(IntPtr pHookHandle); /// <summary> /// 传递钩子 /// </summary> /// <param name="pHookHandle">是您自己的钩子函数的句柄。用该句柄可以遍历钩子链</param> /// <param name="nCode">把传入的参数简单传给CallNextHookEx即可</param> /// <param name="wParam">把传入的参数简单传给CallNextHookEx即可</param> /// <param name="lParam"></param> /// <returns></returns> [DllImport("user32.dll", CallingConvention = CallingConvention.StdCall)] public static extern int CallNextHookEx(IntPtr pHookHandle, int nCode, Int32 wParam, IntPtr lParam); #endregion 私有变量 #region 私有方法 /// <summary> /// 键盘钩子处理函数 /// </summary> /// <param name="nCode"></param> /// <param name="wParam"></param> /// <param name="lParam"></param> /// <returns></returns> /// <remarks>此版本的键盘事件处理不是很好,还有待修正.</remarks> private int KeyboardHookProc(int nCode, Int32 wParam, IntPtr lParam) { //return 1; KeyMSG m = (KeyMSG)Marshal.PtrToStructure(lParam, typeof(KeyMSG)); if (m_pKeyboardHook != IntPtr.Zero) { switch (((Keys)m.vkCode)) { case Keys.LWin: case Keys.RWin: case Keys.Delete: case Keys.Alt: case Keys.Escape: case Keys.F4: case Keys.Control: case Keys.Tab: return 1; } } return 0; } #endregion 私有方法 #region 公共方法 /// <summary> /// 安装钩子 /// </summary> /// <returns></returns> public bool InstallHook() { //IntPtr pInstance = Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().ManifestModule); IntPtr pInstance = (IntPtr)4194304; if (this.m_pKeyboardHook == IntPtr.Zero) { this.m_KeyboardHookProcedure = new HookProc(KeyboardHookProc); this.m_pKeyboardHook = SetWindowsHookEx(idHook, m_KeyboardHookProcedure, pInstance, 0); if (this.m_pKeyboardHook == IntPtr.Zero) { this.UnInstallHook(); return false; } } return true; } /// <summary> /// 卸载钩子 /// </summary> /// <returns></returns> public bool UnInstallHook() { bool result = true; if (this.m_pKeyboardHook != IntPtr.Zero) { result = (UnhookWindowsHookEx(this.m_pKeyboardHook) && result); this.m_pKeyboardHook = IntPtr.Zero; } return result; } [StructLayout(LayoutKind.Sequential)] public struct KeyMSG { public int vkCode; public int scanCode; public int flags; public int time; public int dwExtraInfo; } #endregion 公共方法 } } 这个就是核心的代码 追问: 我有Hook代码,就是不行 回答: 632959910 你加我
采纳哦
采纳哦
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |