假期在家表弟表妹们看到电脑就乱敲键盘和鼠标,没事就按到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#”,把类拿来用用吧 我懒喜欢用别人的成果-_-
完成收工 界面麻就不贴了 反正自己用