Disable/enable the mouse and keyboard - is it possible?

Class library usage, coding and language questions.
Posts: 6
Joined: Wed Jan 16, 2008 11:52 am
Location: Hants, UK

Disable/enable the mouse and keyboard - is it possible?

Post by testMunky » Wed Jan 16, 2008 11:57 am


I've done a search and can't find the info so thought i'd post here :)

Is it possible to disable the keyboard and/or mouse for the duration of the script?


Si :twisted:

User avatar
Support Team
Site Admin
Site Admin
Posts: 12169
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA

Post by Support Team » Wed Jan 16, 2008 5:42 pm

You can block input from mouse and keyboard by calling the WinAPI function BlockInput(bool). Just be sure to call the function from the same thread that runs the automation script, otherwise the automated clicks and keyboard events may also be blocked.

To use this method in C#, include the following definition in your class:

Code: Select all

static extern bool BlockInput(bool block);
Another problem with the BlockInput function is that it sometimes seems to block Ranorex.Element access and actions, too. That's why this functionality is not included in Ranorex by default. So, if your script blocks on a specific line, just enable the input before that line and disable it afterwards again.

Ranorex Support Team