cancel
Showing results for 
Search instead for 
Did you mean: 

How to block keyboard when script running?

SOLVED
Highlighted
Occasional Contributor

How to block keyboard when script running?

How to block keyboard when script running?
1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: How to block keyboard when script running?

Hi,

 

Does this help?

(Note: ages old DelphiScript code that might not work in modern TestComplete and/or Windows and I think that you definitely must consider bitness as described here: https://support.smartbear.com/testcomplete/docs/testing-with/advanced/using-external-functions/calli...)

 
//-------------------------------------------------------------------------------
// Blocks keyboard and mouse input events from reaching applications.
// Function's effect can be cancelled by pressing Ctrl-Alt-Del
procedure StopKeyMouse;
var Def_DLL;
var Def_Proc;
var Lib;
begin
    Def_DLL := DLL.DefineDLL('USER32');
    Def_Proc := Def_DLL.DefineProc('BlockInput', vt_b1, vt_b1);
    Lib := DLL.Load('USER32.DLL', 'USER32');
    Lib.BlockInput(true);
end;
//-------------------------------------------------------------------------------
 
// Unblocks keyboard and mouse input events from reaching applications.
procedure ResumeKeyMouse;
var Def_DLL;
var Def_Proc;
var Lib;
begin
    Def_DLL := DLL.DefineDLL('USER32');
    Def_Proc := Def_DLL.DefineProc('BlockInput', vt_b1, vt_b1);
    Lib := DLL.Load('USER32.DLL', 'USER32');
    Lib.BlockInput(false);
end;
//-------------------------------------------------------------------------------
 
Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================

View solution in original post

10 REPLIES 10
Community Hero

Re: How to block keyboard when script running?

Short answer you can't. Test complete sends real keystrokes and mouse actions when playing back.


Thanks,
Carson

Click the Accept as Solution button if my answer has helped
Occasional Contributor

Re: How to block keyboard when script running?

I do NOT think so.Without keyboard,the scripts can work normally.Any guy can show a code sample?Thanks advance!
Occasional Contributor

Re: How to block keyboard when script running?

I do NOT think so.Without keyboard,the scripts can work normally.Any guy can show a code sample?Thanks advance!
Community Hero

Re: How to block keyboard when script running?

Right, without a physical keyboard hooked up, it will still work.  However, TestComplete "takes over" the UI input on the operating system while it's executing so any keystrokes ore mouse actions done while the automation is running will interfere.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Occasional Contributor

Re: How to block keyboard when script running?




the following ppython code sample dose NOT work in TestComplete ,why?
import time
from ctypes import *
user32 = windll.LoadLibrary('user32.dll')
user32.BlockInput(True);
time.sleep(10);
user32.BlockInput(False);
Community Hero

Re: How to block keyboard when script running?

Define "does not work"? Where is the error?  What error message are you getting?

 

Again... TestComplete needs to be able to interact with the objects on screen.  It needs to be able to simulate keyboard and mouse events and it does so using the operating system.  What is your purpose behind wanting to block the keyboard?  What are you trying to achieve?  Perhaps there is a better way. 


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Occasional Contributor

Re: How to block keyboard when script running?

Below is my answer: 1、There is no error message when running the code,it just sleep 10 seconds but the physical keyboard still can input. 2、I want to block physical keyboard input to avoid unexpected input when the scripts running. 3、TestComplete can work fine even no physical keybaord attached, so if I blocked keyboard input,it can simulate normally.
Community Hero

Re: How to block keyboard when script running?

The answer is this:

 

you can't.  Best practice is that, if an automation is running, the machine should be left untouched.  This can be done with VM's in a console mode or a lab.  


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Community Hero

Re: How to block keyboard when script running?

Hi,

 

Does this help?

(Note: ages old DelphiScript code that might not work in modern TestComplete and/or Windows and I think that you definitely must consider bitness as described here: https://support.smartbear.com/testcomplete/docs/testing-with/advanced/using-external-functions/calli...)

 
//-------------------------------------------------------------------------------
// Blocks keyboard and mouse input events from reaching applications.
// Function's effect can be cancelled by pressing Ctrl-Alt-Del
procedure StopKeyMouse;
var Def_DLL;
var Def_Proc;
var Lib;
begin
    Def_DLL := DLL.DefineDLL('USER32');
    Def_Proc := Def_DLL.DefineProc('BlockInput', vt_b1, vt_b1);
    Lib := DLL.Load('USER32.DLL', 'USER32');
    Lib.BlockInput(true);
end;
//-------------------------------------------------------------------------------
 
// Unblocks keyboard and mouse input events from reaching applications.
procedure ResumeKeyMouse;
var Def_DLL;
var Def_Proc;
var Lib;
begin
    Def_DLL := DLL.DefineDLL('USER32');
    Def_Proc := Def_DLL.DefineProc('BlockInput', vt_b1, vt_b1);
    Lib := DLL.Load('USER32.DLL', 'USER32');
    Lib.BlockInput(false);
end;
//-------------------------------------------------------------------------------
 
Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================

View solution in original post