How To Block Keyboard and Mouse Inputs while Running QTP Scripts
When you are running your Test Scripts, sometimes an accidental button press on your keyboard or mouse may interrupt your run session. To prevent this, QTP 11 provides a method that prevents keyboard and mouse input events from reaching applications.
SystemUtil.BlockInput method: This method prevents keyboard and mouse input events from reaching applications and thus interrupting your run session. After you use this method, the keyword and mouse events are blocked till one of the following things occur –
1. SystemUtil.UnBlockInput method is used.
2. The run session ends or is paused due to run error, breakpoint etc.
3. Ctrl + Alt + Del combination is pressed on the keyboard.
4. A critical system error occurs.
SystemUtil.UnBlockInput method: This method re-enables keyboard and mouse input events after a BlockInput statement was used to block them.
Example: The below example shows how keyboard and mouse events can be blocked/unblocked.
'Block Keyboard & Mouse Inputs SystemUtil.BlockInput 'Code Browser("brBrowser").Page("pgPage").WebEdit("txtSearch").Set "Text" Browser("brBrowser").Page("pgPage").WebButton("btnSearch").Click 'Unblock Keyboard & Mouse Inputs SystemUtil.UnBlockInput