Click here to Skip to main content
15,666,844 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone!!

I am working for in a school project and I need to put in disable my mouse and keyboard, I read a lot of blogs but I found the same solution, the problem is that it doesn't work

//declare this
using System.Runtime.InteropServices;

[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern void BlockInput([In, MarshalAs(UnmanagedType.Bool)]bool fBlockIt);

private void button1_Click(object sender, EventArgs e)


I have a windows 7 laptop, a Microsoft visual studio 2008

Updated 22-Nov-10 6:59am

[System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "BlockInput")]
     [return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
     public static extern bool BlockInput([System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)] bool fBlockIt);

this can work for win 32 but not working win 64 .... can any one help to to do the same for win 64 bit...

thanks in advance
Share this answer
Try this which has answer How can I block keyboard and mouse input in C#?[^]

I recommend this article for you - Processing Global Mouse and Keyboard Hooks in C#[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900