My advertisement unit. Please click here. Thank you!
Using system; using system. collections. generic; using system. LINQ; using system. text; using system. runtime. interopservices; using Microsoft. win32; using system. diagnostics; namespace workhelper {class syshook {[dllimport ("USER32")] public static extern bool blockinput (bool isblock); [dllimport (@ "native. DLL ", entrypoint =" fucksyskey ")] private extern static bool fucksyskey (bool enable); Public void Block Keyandmouse (bool B) {blockinput (B); fucksyskey (B); // lock CTRL + ALT + DEL} Public Delegate int hookproc (INT ncode, int wparam, intptr lparam ); static int hhook = 0; Public const int wh_keyboard_ll = 13; // The lowlevel keyboard is intercepted. If it is wh_keyboard = 2, the system keyboard cannot be intercepted, acrobat Reader gets the keyboard before you intercept it. Hookproc keyboardhookprocedure; // keyboard hook Structure Function [structlayout (layoutkind. sequential)] public class keyboardhookstruct {public int vkcode; Public int scancode; Public int flags; Public int time; Public int dwextrainfo ;} # region dllimport // set hook [dllimport ("user32.dll")] public static extern int setwindowshookex (INT idhook, hookproc lpfn, intptr hinstance, int threadid ); [dllimport ("user32.dll", char Set = charset. auto, callingconvention = callingconvention. stdcall)] // remove the hook public static extern bool unhookwindowshookex (INT idhook); [dllimport ("user32.dll")] // call the next hook 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 getmodul Ehandle (string name); Public void hook_start () {// install the keyboard hook if (hhook = 0) {keyboardhookprocedure = new hookproc (keyboardhookproc ); // hhook = setwindowshookex (2, // keyboardhookprocedure, // getmodulehandle (process. getcurrentprocess (). mainmodule. modulename), getcurrentthreadid (); hhook = setwindowshookex (wh_keyboard_ll, keyboardhookprocedure, getmodulehandle (process. getcurrentprocess (). mainmodul E. modulename), 0); // If Hook setting fails. If (hhook = 0) {hook_clear (); // throw new exception ("hook setting failed! ") ;}}// Cancel the hook event public void hook_clear () {bool retkeyboard = true; If (hhook! = 0) {retkeyboard = unhookwindowshookex (hhook); hhook = 0;} // If the hook fails to be removed, if (! Retkeyboard) throw new exception ("unhookwindowshookex failed. ") ;}// here you can add the desired information to process public static int keyboardhookproc (INT ncode, int wparam, intptr lparam) {If (ncode> = 0) {keyboardhookstruct KBH = (keyboardhookstruct) Marshal. ptrtostructure (lparam, typeof (keyboardhookstruct); // MessageBox. show (KBH. vkcode. tostring (); If (KBH. vkcode! = 32) {return 1 ;}} return callnexthookex (hhook, ncode, wparam, lparam) ;}# endregion }}call syshook H = new syshook (); H. hook_start (); // lock the keyboard H. hook_clear (); // unlock H. blockkeyandmouse (true); // lock the keyboard and mouse, including the task manager hotkey