Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Buen día, necesito bloquear el mouse y teclado del PC cuando ejecute una funcion en C#. alguien me puede ayudar con esto ?

Translation: Hello, I need to block the mouse and keyboard of the PC while executing a function in C#. Can someone help me with this?

What I have tried:

intente con el Blockinput(); pero somo se bloquean los dispositivos con la aplicacion

Translation: Try with the Blockinput (); but (somo) the devices are blocked by the application
Posted
Updated 23-Nov-17 4:40am
v3
Comments
phil.o 22-Nov-17 12:14pm    
This is an english-language site only. Please next time use a translator and translate yourself your question in english.
Dave Kreskowiak 22-Nov-17 13:24pm    
Why on earth would you need this? Remember, Windows is a SHARED SYSTEM. Other applications are running at the same time that might need the mouse and keyboard.

1 solution

A general way of blocking the cursor is to set it to wait

C#
Cursor = Cursors.WaitCursor;


I'd tend to agree with the people commenting, that you'll NEVER get compliments for taking peoples keyboard, after all, they may be wanting to alt-tab to change focus for instance. Preventing this would be characterized as a virus!

But suppose you only mean in your own application, it becomes relevant what type of application you are using(?)

Essentially you can achieve what you will by listening in on key-down event

C#
private void MyKeyDownEventHandler(object sender, KeyEventArgs e)
{
        e.SuppressKeyPress = true;
}

Then simply remove your event listener when you want the keyboard to work.
 
Share this answer
 
Comments
Alex212016 23-Nov-17 16:40pm    
I'm working on a tool for RPA, the issue is that I want to develop a function in the tool that blocks the mouse and the keyboard so that the user can not touch the computer while the automation completes the task that asks
CHill60 23-Nov-17 18:25pm    
If you don't want the user to "touch the computer. .." then you're doing the RPA in the wrong place. Consider using a service or a server process. RPA is NOT preventing a user using their own PC!

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