键盘鼠标锁定小程序

       假期在家表弟表妹们看到电脑就乱敲键盘和鼠标,没事就按到POWER键,让我很是头痛,回到学校没事做就写了个锁定键盘鼠标的程序,这下嘿嘿:)

      鼠标好办,左右互换:

  [DllImport("user32.dll")]
  private extern static bool SwapMouseButton(bool fSwap);

       隐藏光标

  [DllImport("user32.dll")]  
  static extern bool ShowCursor(bool bShow);

锁定鼠标在某区域

  [DllImport("user32.dll")]
  static extern bool ClipCursor(ref RECT lpRect);

键盘事件就要用全局HOOK了,可是把SetWindowsHook最后一个参数为0后根本没反应-_-,一查才知道

You cannot implement global hooks in Microsoft .NET Framework. To install a global hook, a hook must have a native dynamic-link library (DLL) export to inject itself in another process that requires a valid, consistent function to call into. This requires a DLL export, which .NET Framework does not support. Managed code has no concept of a consistent value for a function pointer because these function pointers are proxies that are built dynamically

这时候就我就选择去CodeProject,终于找到一个篇“Processing Global Mouse and Keyboard Hooks in C#”,把类拿来用用吧  我懒喜欢用别人的成果-_-

完成收工  界面麻就不贴了 反正自己用

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值