Answer if it is a Desktop application, in the case of Web application, I know no solution.
First of all, this is not a cool thing to do, in case you have some antivirus or something like this your application will be detected as virus, even because many keyloggers use the same technique.
For this you will need to perform some low-level Hooks in the system.
There are many ways to do this, you can do 'at hand', or use some frameworks.
In the example below I will do from a framework that this in that answer here.
Github Framework Globalmousekeyhook
nuget install MouseKeyHook
My code in Windows Forms looks like this:
private IKeyboardMouseEvents m_GlobalHook;
private void Form1_Load(object sender, EventArgs e)
{
m_GlobalHook = Hook.GlobalEvents(); //inicia instancia do hook
m_GlobalHook.KeyDown += MetodoKeyPressHook; //cria um hook para o metodo
}
private void MetodoKeyPressHook(object sender, KeyEventArgs e)
{
//apenas para o botao espaço:
if(e.KeyCode == Keys.Space)
e.Handled = true;
//ou simplesmente para todas as teclas:
e.Handled = true;
//exemplo abaixo ele deixa normal as teclas e não ignora.
e.Handled = false;
}
PS: be careful when debugging :D.
Good afternoon, You need to make this lock in a windows form or web application?
– user37681
You need to make this lock in a windows form or web application?
– Ricardo
Take a look at this article. http://www.codeproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-C
– JcSaint