site
stats
By Anish Pillai Anish Pillai Posted under General

How To Block Keyboard and Mouse Inputs while Running QTP Scripts

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×

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

If you liked this article, you can join our blog to get free email updates directly in your inbox.

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×
  • nidhish

    Hi,

    please update SystemUtil.UnBlockInput method in article in place of SystemUtil.BlockInput for unblocking the event

    • Hi Nidhish,

      Thanks for pointing out the mistake in the article. I have replaced SystemUtil.BlockInput with SystemUtil.UnBlockInput. Please visit other articles in the blog and let us know your comments on them.

      Anish

  • Ramya

    Does Replay type as mouse work when using SystemUtil.BlockInput & SystemUtil.UnBlockInput . Please confirm

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Email -- 0 Flares ×